php filesize stat failed for
PHP: filesize() stat failed with link
I’m randomly getting download errors from a link on a page. I also simplified the link to a directory for easy usage in emails for users.
On the main page the link looks like this:
On my server, that’s a directory with an index.php in it which looks like this:
Again, the reason I do this is so it’s a simple link to send to users in email like, «http://myPage.com/Mac» and «http://myPage.com/Windows».
The weird thing is that it mostly works. but sometimes it doesn’t.
What am I doing wrong?
2 Answers 2
It’s hard to know precisely what’s wrong unless you check for errors on your readfile() call.
where you could just as easily do
and read the zip file from the local file system to send to your user.
What’s more, filesize(‘../downloads/myApp_Mac.zip’); will yield a numerical value quickly and send it in the Content-Length header. That will allow the browser, by knowing the total size of the file you’re sending, to display a meaningful progress bar.
You should remove the Accept-Ranges header; the php program you showed us doesn’t honor range requests. If you lie to the browser by telling it you do honor those requests, the browser may get confused and corrupt the downloaded copy of your file. That will baffle your user.
Your Content-Disposition header is perfect. It defines the filename to be used on your user’s machine in the downloads folder.
Simple operations are more reliable, and this may help you.
The reason you got stat failed with link as an error message is this: stat(2) is a operating-system call that operates on files in local and mounted file systems.
As previously mentioned by O. Jones you should definitely always use your local file path.
If all else fails I have no idea what server your running this on but if you continue to have issues I would recommend monitoring which processes your machine is running while paying close attention to ram and IO usage. I’ve have encountered bad/misbehaving services that run periodically using 99% of my IO or ram for short intervals at a time that caused a few really odd and unexpected errors.
Warning: filectime(): stat failed for path
I am trying to get the date in which a file was modified or created with PHP. To do this I am using filectime function but it is giving me always the following error:
Warning: filectime(): stat failed for path
where path is the route in which I have stored the file.
The route is something similar to this:
and I have to replace the url to codify the spaces of the file:
If I do this I can use a link to open this file on my browser but it shows the warning that I have put before if I try to use the same path on filectime function.
Am I missing something?
1 Answer 1
The filectime function expects a string path as a parameter. It is just a wrapper function over the usage of Posix stat system call.
int stat(const char *pathname, struct stat *buf);
So, it expects a parameter as though it’s on your filesystem. The URL gets encoded to have a neat white-space-less identifier on the server side to execute appropriate scripts.
Don’t bother with that «codification»! Just use a standard string path as you’d use on your UNIX shell, relative to the script directory.
In this case, just provide the right path to the PHP function!
«app»:»PHP»,»message»:»filesize(): stat failed for #12897
Comments
fbassas commented Dec 17, 2014
HI,
we have owncloud 7.0.4 on a ubuntu 14.04 LTS
Now that we have serveral users we are getting messages like this on our owncloud.log
Our firs aproach to solve is have been to use occ with the user id :
occ files:scan b9e1009e-7f3f-102a-8c82-fdcd95ab32a5
And it seems it was enough, but after short, messages appeared again.
Can it be a bug? Something related to database integrity?
Thanks for your help
The text was updated successfully, but these errors were encountered:
We are unable to convert the task to an issue at this time. Please try again.
The issue was successfully created but we are unable to update the comment at this time.
LukasReschke commented Dec 17, 2014
Thanks a lot for reporting issues back to us!
We need some more information to properly support you with your issue!
Can I ask you to follow our guidelines for submitting bugs as described here: https://github.com/owncloud/core/blob/master/CONTRIBUTING.md
fbassas commented Dec 19, 2014
Hi Lukas, thanks for your answer.
Here they go the details:
Steps to reproduce
After some time running owncloud.
Expected behaviour
Tell us what should happen
Actual behaviour
Cpu usage grows up and messages with string «»filesize(): stat failed» appears in owncloud.log
Server configuration
Operating system:
ubuntu 14.04 LTS
Web server:
apache
Database:
mysql 5.5
PHP version:
5.5.9
ownCloud version: (see ownCloud admin page)
/.0.4
Updated from an older ownCloud or fresh install:
Updated from 6
List of activated apps:
Activity
Bookmarks
Calendar
Deleted files
Documents
Firtst Run Wizard
Full Text Search
LDAP user and group backend
PDF Viewer
Pictures
Shared Files
Text Editor
Udater
Versions
Video Viewer
Charts
Shorty
The content of config/config.php:
Are you using external storage, if yes which one: local/smb/sftp/.
NO
Are you using encryption: yes/no
NO
Client configuration
Browser:
default
Operating system:
Windows,Linux
and the line that causes the problem:
As you can see, file exists because it is checked.
Problematic line of code is included in smarty_internal_cacheresource_file.php (part of Smarty lib v3.0.6)
App is run on UNIX system, external hosting.
Any ideas? Should I post more details?
3 Answers 3
I used filemtime successfully without checking «file_exists» for years. The way I have always interpreted the documentation is that FALSE should be returned from «filemtime» upon any error. Then a few days ago something very weird occurred. If the file did not exist, my Cron job terminated with a result. The result was not in the program output but rather in the Cron output. The message was «file length exceeded». I knew the Cron job ended on the filemtime statement because I sent myself an email before and after that statement. The «after» email never arrived.
I inserted a file_exists check on the file to fix the Cron job. However, that should not have been necessary. I still do not know what was changed on the hosting server I use. Several other Cron jobs started failing on the same day. I do not know yet whether they have anything to do with filemtime.
Not the answer you’re looking for? Browse other questions tagged php unix smarty or ask your own question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.9.17.40238
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.