使用laravel 4进行干预\ Image\Exception\NotReadableException

fre*_*dev 8 php file-upload image laravel laravel-4

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

Intervention \ Image \ Exception \ NotReadableException
Run Code Online (Sandbox Code Playgroud)

图像源不可读

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;
    }
Run Code Online (Sandbox Code Playgroud)

如果它可以帮助你,我也在MAC OS上使用MAMP和Sublime Text 3.

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

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',
);
Run Code Online (Sandbox Code Playgroud)

(我没有向您显示我的视图的重定向,但它对我控制器的这一部分工作正常)

这是我的表单代码(使用刀片laravel模板):

@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
Run Code Online (Sandbox Code Playgroud)

当然我已经在官方网站image.intervention.io/getting_started/installation(url)之后安装了Intervention Image软件包 .

如何让我的文件"可读"?或者解决这个错误?

The*_*pha 15

改变这个:

$file = Image::make('url_Avatar');
Run Code Online (Sandbox Code Playgroud)

对此:

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

阅读有关Laravel文档的更多信息.