file_exists 由于未知原因返回 false

发布于 2024-10-15 11:47:50 字数 1012 浏览 1 评论 0原文

我有以下文件:

/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撩起发的微风 2024-10-22 11:47:50

尝试转义文件名中的空格。

/home/user/public_html/web-site.org/download/audio/1999/01-03\ Good\ News.mp3

Try escaping the spaces in the filename.

/home/user/public_html/web-site.org/download/audio/1999/01-03\ Good\ News.mp3
夕色琉璃 2024-10-22 11:47:50

哇...我失败了...史诗般的失败...我的用户路径错误

wow.... fail on my part.... epic fail.... my user path was wrong

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文