干涉\ Image \ Exception \ NotReadableException使用laravel 4 [英] Intervention \ Image \ Exception \ NotReadableException using laravel 4

查看:609
本文介绍了干涉\ Image \ Exception \ NotReadableException使用laravel 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 laravel 4 ,并安装了 Intervention Image软件包 。当我在我的代码中使用方法 - 调整大小, - >移动等等等等等等...我有这个错误:

 干预\ Image \ Exception \ NotReadableException 

图像源不可读

 打开: /Applications/MAMP/htdocs/myNameProject/vendor/intervention/image/src/Intervention/Image/AbstractSource.php 

break;
$ b $ case $ this-> isFilePath():
return $ this-> initFromPath($ this-> data);
break;

默认值:
抛出新的Exception \NotReadableException(Image source not readable);
break;



$ b我也在MAC OS上使用 MAMP和Sublime Text 3如果它可以帮助你的话。



这是我的控制器中的代码:

$ b

  public function upload(){

// *****上载文件(在服务器上是图像,但是是数据库中的Url ** *** //

//获取输入文件
$ file = Image :: make('url_Avatar');

//设置一个寄存器路径到上传的文件
$ destinationPath = public_path()。'upload /';

//有客户端扩展名加载文件,并为上传的文件设置一个随机名,产生一个随机的字符串(32)。'。'。$ file-> getClientOriginalExtension();
$ $ file-> move($ destinationPath,$ filename);

//设置$文件以调整格式大小并保存为数据库中的url
$ file =图片::使($图像 - > getRealPath ()) - >调整大小( 200’ , 200’ ) - >保存(上传/'.$文件名);

// ***** VALIDATORS INPUTS和RULES *****
$ inputs = Input :: all();
$ rules = array(
'pseudo'=>'required | between:1,64 | unique:profile,pseudo',
// urlAvatar是数据库中的一个url,但是我们注册作为服务器上的图像
'url_Avatar'=>'required | image | min:1',
);

(我没有向您显示我的视图的重定向,但它的工作正常我的控制器的这一部分)这里是我的表单代码(使用刀片laravel模板):
$ b
$ b

  @extends('layout.default')
@section('title')
我的项目名称 - EditProfile
@stop

@section('content')
{{Form :: open(array('url'=>'uploadAvatar','files'=> true) )}}

< p>
{{Form :: label('pseudo','pseudo(*):')}}
{{Form :: text('pseudo',Input :: old('nom')) }}
< / p>
@if($ errors-> has('pseudo'))
< p class ='error'> {{$ errors-> first('pseudo')}}< / p>
@endif
< br>
< br>

< p>
{{Form :: label('url_Avatar','Avatar:')}}
{{Form :: file('url_Avatar',Input :: old('Url_Avatar'))}}
< / p>
@if($ errors-> has('url_Avatar'))
< p class ='error'> {{$ errors-> first('url_Avatar')}}< / p>
@endif
< br>
< br>

< p>
{{Form :: submit('Validate your avatar')}}
< / p>
$ b $ {{Form :: close()}}
@stop

当然,我已经安装了干预图片包 官方网站 image.intervention.io/getting_started/installation 如何使我的文件可读?或者解决此错误?>(url)。

解决方案

c> $ file = Image :: make('url_Avatar');

至此:

  $ file = Input :: file('url_Avatar'); 
// ...
$ filename ='...';
Image :: make($ file-> getRealPath()) - > resize('200','200') - > save($ filename);

详细了解 Laravel文档


I'm using laravel 4 and I installed the Intervention Image package. When I'm using it in my code whith method ->resize, ->move etc etc etc... I have this error:

Intervention \ Image \ Exception \ NotReadableException

Image source not readable

open: /Applications/MAMP/htdocs/myNameProject/vendor/intervention/image/src/Intervention/Image/AbstractSource.php

        break;

        case $this->isFilePath():
            return $this->initFromPath($this->data);
            break;

        default:
            throw new Exception\NotReadableException("Image source not readable");
            break;
    }

I'm also using MAMP and Sublime Text 3 on MAC OS if it could help you.

This is my code in my controller:

public function upload() {

//***** UPLOAD FILE (on server it's an image but an Url in Database *****//

// get the input file
$file = Image::make('url_Avatar');

//set a register path to the uploaded file
$destinationPath = public_path().'upload/';

//have client extension loaded file and set a random name to the uploaded file, produce a random string of length 32 made up of alphanumeric characters [a-zA-z0-9]
$filename = $destinationPath . '' . str_random(32) . '.' . $file->getClientOriginalExtension();
//$file->move($destinationPath,$filename);

//set $file in order to resize the format and save as an url in database
$file= Image::make($image->getRealPath())->resize('200','200')->save('upload/'.$filename);

//*****VALIDATORS INPUTS and RULES*****
$inputs = Input::all();
$rules = array(
'pseudo' => 'required|between:1,64|unique:profile,pseudo',
//urlAvatar is an url in database but we register as an image on the server
'url_Avatar' => 'required|image|min:1',
);

(I don't show you the redirect of my view, but it's worked fine for this section of my controller)

here is my form code (using blade laravel template):

@extends('layout.default')
@section('title')
Name Of My Project - EditProfile
@stop

@section('content')
{{Form::open(array('url'=>'uploadAvatar','files' => true))}}

<p>
{{Form::label('pseudo','pseudo (*): ')}}
{{Form::text('pseudo',Input::old('nom'))}}
</p>
@if ($errors->has('pseudo'))
<p class='error'> {{ $errors->first('pseudo')}}</p>
@endif
<br>
<br>

<p>
{{Form::label('url_Avatar','Avatar: ')}}
{{Form::file('url_Avatar',Input::old('Url_Avatar'))}}
</p>
@if ($errors->has('url_Avatar'))
<p class='error'> {{ $errors->first('url_Avatar')}}</p>
@endif
<br>
<br>

<p>
{{Form::submit('Validate your avatar')}}
</p>

{{Form::close()}}
@stop

Of course I have installed Intervention Image package following the official website image.intervention.io/getting_started/installation (url).

How can I make my file "readable"? or resolve this error?

解决方案

Change this:

$file = Image::make('url_Avatar');

To this:

$file = Input::file('url_Avatar');
// ...
$filename = '...';
Image::make($file->getRealPath())->resize('200','200')->save($filename);

Read more about file on Laravel documentation.

这篇关于干涉\ Image \ Exception \ NotReadableException使用laravel 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆