php file_exists is returning false even if file exist on my linux

自闭症网瘾萝莉.ら 提交于 2019-12-03 16:32:23

The permission of the file alone is not sufficient for php to assess file_exists. the process that runs php also needs permission to traverse all the parent directories of that file to get to it.

Check them one by one and verify that php can read and enter (r-x)

ls -ald /var
ls -ald /var/www
ls -ald /var/www/html
ls -ald /var/www/html/smic
ls -ald /var/www/html/smic/upload
ls -ald /var/www/html/smic/upload/28

Clutching at straws here...

Try su - apache (or whatever the user your webserver runs as.. apache2, www-data etc..) and then traversing the directory.

Are there any .htaccess files knocking about, or any other restrictions on your apache configuration?

Gee, this was a pretty tuff one. I always make sure when I copy anything from the web to first paste it into a normal texteditor in order to remove all strange/hidden characters, then copy the whatever again and paste it into my dev tool.

As I mentioned somewhere in a comment, I did pwd and copied the text form my virtual server to my osx. But what I didn't think about/know was that strange/hidden characters could follow if I did that from my linux server, hence I didn't make sure to copy everything via texteditor.

I remembered that I had problem quite some time ago when I copied from the web and figured this may be a similar kind of problem. I opened my script in an hex editor. And what did I find... '/var' looked lite this: '/var'. Removing the strange characters fixed the problem.

Thank you all for your comments above. Hope those can help someone else and perhaps it has helped me without even knowing it (since I did a lot of things based on your comments).

what's about the access rights to the folder? the path $file = 'file:///var/www/html/smic/upload/28/ul.txt'; is incorrect. Try the php script copy to folder upload and file='28/ul.txt';. The folder must be readable.

Try to open the file using $file = '/upload/28/ul.txt';

From the php.net manual, "Upon failure, an E_WARNING is emitted." make sure error reporting is set to a level that will show warnings and try it.

Also, "This function returns FALSE for files inaccessible due to safe mode restrictions. However these files still can be included if they are located in safe_mode_include_dir.". You're not running in php safe mode are you? phpinfo() should tell you.

Where is your php file located? If within the "html" folder, then use a relative path like $file = "smic/upload/28/ul.txt";

Perhaps, in a name of the file there is a whitespace symbol. It's important.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!