file_exists 由于未知原因返回 false
我有以下文件:
/home/user/public_html/web-site.org/download/audio/1999/01-03 Good News.mp3
问题是抛出错误并且文件存在时退出。我正在检查 file_exists,因为我稍后要执行 copy()
,但由于文件不存在而失败。我托管在 hostGator 上,我对这些 mp3 的权限是 755
。
if (!file_exists('/home/user/public_html/web-site.org/download/audio/'.$sermon['year'].'/'.$sermon['file'])) {
echo "Oops, file doesn't exist: <b>/home/user/public_html/web-site.org/download/audio/".$sermon['year']."/".$sermon['file']."</b>";
exit;
}
会不会是文件名中的空格?我有大约 1,100 个音频文件需要处理,因此手动更改文件名将是一场噩梦...
update
urlencode()
和 trim()
对文件名不起作用
str_replace(' ', '-', $sermon['file'])
对文件名不起作用(将文件名本身中的空格更改为破折号后)
我检查过文件所在文件夹的权限为 700
,我将其更改为 755
,但没有效果。
更新
我在另一个线程中读到,路径中任何位置的 .
都可能会导致问题...所以我将 .org
更改为 _org
并且问题仍然存在,因此我恢复了这些更改。
I have the following file:
/home/user/public_html/web-site.org/download/audio/1999/01-03 Good News.mp3
The problem is that the error is thrown and the file is exited when it exists. I'm checking for file_exists because I'm doing a copy()
later and it's failing cause the file doesn't existing. I'm hosted on hostGator and my permissions on these mp3s are 755
.
if (!file_exists('/home/user/public_html/web-site.org/download/audio/'.$sermon['year'].'/'.$sermon['file'])) {
echo "Oops, file doesn't exist: <b>/home/user/public_html/web-site.org/download/audio/".$sermon['year']."/".$sermon['file']."</b>";
exit;
}
Could it be the space in the filename? I have about 1,100 audio files to process, so changing the filename manually would be a nightmare...
update
urlencode()
and trim()
on the filename has no effect
str_replace(' ', '-', $sermon['file'])
on the filename doesn't work (after changing spaces to dashes in the filename itself)
I checked the permissions on the folder the file is in, it WAS 700
and I changed it to 755
and it had no effect.
update
I read in another thread that having a .
in the path anywhere could cause a problem... so I changed .org
to _org
and the problem persisted, so I've reverted those changes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试转义文件名中的空格。
Try escaping the spaces in the filename.
哇...我失败了...史诗般的失败...我的用户路径错误
wow.... fail on my part.... epic fail.... my user path was wrong