干预\图像\异常\NotReadableException无法找到文件()

问题描述 投票:0回答:8

我有这个代码来保存我的帖子图像,它返回错误:

Intervention \ Image \ Exception \ NotReadableException
Unable to find file ().

我的代码:

if ($request->hasFile('image')) {
        $image = $request->file('image');
        $filename = 'food' . '-' . time() . '.' . $image->getClientOriginalExtension();
        $location = public_path('images/');

        Image::make($image)->resize(800, 400)->save($location);


        $food->image = $filename;

      }

我使用 laravel 4 从 Intervention \ Image \ Exception \ NotReadableException 得到了这段代码 但在此之前我有这段代码

if ($request->hasFile('image')) {
        $image = $request->file('image');
        $filename = 'food' . '-' . time() . '.' . $image->getClientOriginalExtension();
        $location = public_path('images/');
        $request->file('image')->move($location, $filename);

        $food->image = $filename;

      }

它工作得很好,我更改代码的原因是能够调整图像大小,仅此而已。

谢谢。

php laravel intervention
8个回答
4
投票

您必须更改 Windows/临时文件的权限。启用用户组的读取权限。


2
投票

就我而言,我通过在 php.ini 中添加此条目来使其正常工作

upload_tmp_dir = "C:\Users\<NAME>\AppData\Local\Temp"

并重新加载服务器


1
投票

我已经测试了你的代码并修复了错误。现在工作正常。

$file = $request->file('image');

if ($request->hasFile('image')) {
    $image = $request->file('image');
    $filename = 'food' . '-' . time() . '.' . $image->getClientOriginalExtension();
    $location = public_path('images/'. $filename);

    Image::make($image->getRealPath())->resize(800, 400)->save($location);
}

0
投票

试试这个

$image = $request->file('image');
$location = public_path('images/');
$filename = $location. ''.'food' . '-' . time() . '.' . $image->getClientOriginalExtension();
Image::make($image->getRealPath())->resize('800','400')->save($filename);

更新

$image = $request->file('image');
$location = public_path('images/');
Image::make($image)->resize('800','400')->save($location.$filename);

另请检查此帖子此处


0
投票
$originalImage = 'images/1.jpg';
Image::make($originalImage);

0
投票

我尝试了更多,最后我得到了它。我发现index.php文件是否在外部公共文件夹中使用然后这个问题出现。按照这个方法就可以解决问题了。

    $image = $request->file('image');

    $input['imagename'] = hexdec(uniqid()).$image->getClientOriginalName();

    $location = public_path("upload/image");

    $imgs = Image::make($image->getPathname());

    $imgs->resize(300 , 300, function ($constraint) { $constraint->aspectRatio(); })->save($location.'/'.$input['imagename']);

0
投票

我尝试了很多,终于成功了。按照这段代码我认为解决了你的问题

$location = "assets/images/brand";`
$file = $request->image;
$filename =uniqid().time().'.'.$file->getClientOriginalExtension();
$image = Image::make(file_get_contents($file))->resize('600','600')->save($location.'/'.$filename);

0
投票

当前干预版本不支持PHP版本。尝试升级/降级 php 版本。

© www.soinside.com 2019 - 2024. All rights reserved.