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
File_exists always false in laravel 4
提问by Vuk Stankovi?
I have written small CMS in Laravel 4 and I was working on it using wamp. Application was in www
folder 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 root
folder 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.php
file? (It's generaly in public
folder), file_exists()
is relative to it, so if your installation is: public_html/public/index.php
and repo/images
is on public
folder you should check for: file_exists('repo/images...');
二、laravel的index.php
文件在哪里?(通常在public
文件夹中),file_exists()
是相对于它的,所以如果您的安装是:public_html/public/index.php
并且repo/images
在public
文件夹中,您应该检查: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 public
folder to public_html
. This way, you could check file existence relatively to public_html
folder.
Laravel 旨在将其文件保留在公共访问之外,因此我建议您将 Laravel 的文件和文件夹放在根目录中,/
同时将文件夹中的所有内容移动public
到public_html
. 这样,您可以检查相对于public_html
文件夹的文件存在。
file_exists('repo/images...');
file_exists('../app/views/hello.blade.php');
...