PHP 无法找到文件,即使它存在
每个人。
我正在使用 图像调整器脚本 来调整 JPG 图像的大小。它在我的远程服务器上运行良好,但不幸的是它在客户端服务器上不起作用。 :-|
这些目录是可写的(权限设置为 777)。我得到的只是:
Error: image does not exist: /home/content/u/s/e/username/correct/path/to/existing/file.jpg
这是可能有助于调试的代码:
// Images must be local files, so for convenience we strip the domain if it's there
$image = preg_replace('/^(s?f|ht)tps?:\/\/[^\/]+/i', '', (string) $_GET['image']);
// ...
// Strip the possible trailing slash off the document root
$docRoot = preg_replace('/\/$/', '', DOCUMENT_ROOT);
//...
if (!file_exists($docRoot . $image))
{
header('HTTP/1.1 404 Not Found');
echo 'Error: image does not exist: ' . $docRoot . $image;
exit();
}
请注意,作为开发人员,我已被授予访问根目录的子目录的权限。
我希望我已经把问题案例说清楚了。我对幕后发生的事情感到茫然。非常感谢帮助
Everyone.
I am using an image resizer script that resizes JPG images. It worked fine on my remote server but unfortunately it doesn't work on the client's server. :-|
The directories are writable (permission is set to 777). All I am getting is:
Error: image does not exist: /home/content/u/s/e/username/correct/path/to/existing/file.jpg
Here's the bit of the code that may be helpful in debugging:
// Images must be local files, so for convenience we strip the domain if it's there
$image = preg_replace('/^(s?f|ht)tps?:\/\/[^\/]+/i', '', (string) $_GET['image']);
// ...
// Strip the possible trailing slash off the document root
$docRoot = preg_replace('/\/$/', '', DOCUMENT_ROOT);
//...
if (!file_exists($docRoot . $image))
{
header('HTTP/1.1 404 Not Found');
echo 'Error: image does not exist: ' . $docRoot . $image;
exit();
}
Please note that as a developer I have been given permission to access a subdirectory of the root directory.
I hope I made the problem case clear. I am at a loss as to what's going on behind the scene. Help is much apreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PHP 必须能够访问该文件的所有目录,而不仅仅是文件本身。如果它没有对所有目录的权限,则相当于添加“免费!拿一个!”诺克斯堡金库内的小册子分发器 - 无用。
PHP has to have access to all the directories leading up to the file, not just access to the file itself. If it doesn't have permissons on ALL of the directories, it's the equvialent of putting a "Free! take one!" pamphlet dispenser inside a vault inside Fort Knox - useless.