【问题标题】:PHP Not Able to Find File Even Though It ExistsPHP 无法找到文件,即使它存在
【发布时间】:2011-08-29 03:04:50
【问题描述】:

每个人。

我正在使用 image resizer script 来调整 JPG 图像的大小。它在 my 远程服务器上运行良好,但不幸的是它在客户端的服务器上不起作用。 :-|

目录是可写的(权限设置为 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();
}

请注意,作为开发人员,我已获得访问根目录子目录的权限。

我希望我把问题案例说清楚了。我不知道幕后发生了什么。非常感谢您的帮助

【问题讨论】:

  • 您的 preg_replace 将因简单的 http 请求而失败(您的请求仅匹配安全(s)协议。不确定在这种情况下是否重要。
  • @brombomb,感谢您指出这一点。我想这不是问题,因为它在我的服务器上没有任何问题。

标签: php file-permissions directory-permissions


【解决方案1】:

PHP 必须有权访问指向文件的所有目录,而不仅仅是访问文件本身。如果它对所有目录都没有权限,则相当于放置“免费!拿一个!”诺克斯堡金库内的小册子分发器 - 没用。

【讨论】:

  • 这是否意味着root用户需要更改权限?如果是这样,它应该设置为什么?
  • 可能,取决于目录的所有权。以 root 身份执行此操作只是保证您能够更改权限。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-26
  • 2015-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多