我得到一个错误 finfo::finfo() expects parameter 2 to be a valid path, string given
我在 Symfony 中查看了 Documentation并且它说这个函数返回 The mime type 或 NULL,如果没有可以猜到的话
但我不太明白为什么它找不到 mime 类型。
我的路线
路线::获取(
'/图片/{文件}',
'ImageController@getImage'
);
我的网址是 www.example.com/image/logo.png
我的图像 Controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class ImageController extends Controller {
public function getImage($filename) {
$path = \Config::get('assets.images') . $filename;
$file = new \Symfony\Component\HttpFoundation\File\File($path);
// Make a new response out of the contents of the file
// Set the response status code to 200 OK
$response = \Response::make(
\File::get($path),
200
);
// Modify output's header.
// Set the content type to the mime of the file.
// In the case of a .jpeg this would be image/jpeg
$response->header(
'Content-type',
$file->getMimeType()
);
// We return our image here.
return $response;
}
}
$file->getMineType()
是问题,当我 var_dump($file)
我得到 object(Symfony\Component\HttpFoundation\File\文件)[185]
private 'pathName' (SplFileInfo) => string '/home/vagrant/Code/project/storage/assets/images/logo.png' (length=55)
私有(private)“文件名”(SplFileInf
我有点困惑为什么 png 文件类型为 null 而其他文件类型也是如此。
我已经缩小问题范围,错误来自 FileBinaryMimeTypeGuesser我不知道 magicFile
可能是什么。
最佳答案
你有没有检查你的 php.ini 是否在 php.ini 中启用了文件信息扩展
您可以试试,如果所有文件类型都出现同样的情况,很可能是扩展名被禁用了,所以:
;extension=php_fileinfo.dll
我需要被激活所以:
extension=php_fileinfo.dll
在linux中我认为是
extension=fileinfo.so
在 PHP Fileinfo functions 中阅读有关文件信息的更多信息
取消注释 php.ini 文件中的那一行,重新启动 apache 并测试
关于php - getMimeType 函数为 Symfony 上的 FileinfoMimeTypeGuesser 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32161667/