Laravel 4 中的 File_exists 总是错误的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17733423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:09:23  来源:igfitidea点击:

File_exists always false in laravel 4

phplaravellaravel-4

提问by Vuk Stankovi?

I have written small CMS in Laravel 4 and I was working on it using wamp. Application was in wwwfolder and everything was working fine. When I have finished with development, I moved an application to my live server and I have put application in rootfolder of my hosting (folder above public_html). In some functions I'm checking if some files exist, and while I was on wamp, everything worked, but now file_exists()always returns false. Folder permissions of the folder where files are stored are set to 755, and files are with same permissions.

我在 Laravel 4 中编写了小型 CMS,我正在使用 wamp 进行开发。应用程序在www文件夹中,一切正常。完成开发后,我将一个应用程序移动到我的实时服务器,并将应用程序放在root我的托管文件夹(上面的文件夹public_html)中。在某些函数中,我正在检查某些文件是否存在,当我在 wamp 时,一切正常,但现在file_exists()总是返回false. 存放文件的文件夹的文件夹权限设置为755,文件的权限相同。

I have already tried clearstatcache()and Safe mode cannot be an issue since it was removed in PHP 5.4. Any other ideas?

我已经尝试过clearstatcache()并且安全模式不会成为问题,因为它在 PHP 5.4 中被删除了。还有其他想法吗?

if(file_exists('public_html/repo/images/testimage.jpg')){
    //do something
}
else{
    echo "error";
}

I have checked several times, and file does exists if I try to access it via url

我已经检查了几次,如果我尝试通过 url 访问它,文件确实存在

回答by Blue Genie

Well, first you said you were in WAMP, it could be that folders were having uppercases. Remember, windows is not case-sensitive for folder while linux is.

好吧,首先你说你在 WAMP 中,可能是文件夹有大写。请记住,windows 对文件夹不区分大小写,而 linux 是。

Second, where's laravel's index.phpfile? (It's generaly in publicfolder), file_exists()is relative to it, so if your installation is: public_html/public/index.phpand repo/imagesis on publicfolder you should check for: file_exists('repo/images...');

二、laravel的index.php文件在哪里?(通常在public文件夹中),file_exists()是相对于它的,所以如果您的安装是:public_html/public/index.php并且repo/imagespublic文件夹中,您应该检查:file_exists('repo/images...');

Laravel is designed to keep its files outside of public access, so I suggest you put laravel's files and folders in the root /while moving everything in publicfolder to public_html. This way, you could check file existence relatively to public_htmlfolder.

Laravel 旨在将其文件保留在公共访问之外,因此我建议您将 Laravel 的文件和文件夹放在根目录中,/同时将文件夹中的所有内容移动publicpublic_html. 这样,您可以检查相对于public_html文件夹的文件存在。

file_exists('repo/images...');
file_exists('../app/views/hello.blade.php');
...