抛出新的 FileException('File must be readable.');

throw new FileException('File must be readable.');

我正在使用 Laravel ,以下代码在我的本地机器上运行 (Mac)

$Avatarpath =  base_path()."/uploads/image/avatar.png"
$filePath   =  base_path()."/uploads/image/myimage.png" //which gives "/var/www/myproject/uploads/image/myimage.png"

return Response::download(file_exists($filepath) ? $filepath :$Avatarpath);

但是当我在 linux (Centos) 服务器上部署相同的代码时,它会抛出以下异常

throw new FileException('File must be readable.'); 

附加信息:“上传”文件夹具有 drwxr-xr-x (775) 权限

感谢您有兴趣解决此问题。

如果函数 http://php.net/manual/en/splfileinfo.isreadable.php 返回 false,则会抛出此异常。

您的文件权限必须拒绝读取文件。

重要的是文件本身的权限也是正确的!

通常在这种情况下,您应该 运行 chmod 使用递归标志 (-R):

chmod -R 775 uploads/