干预图像异常 NotReadableException使用laravel 4 [英] Intervention Image Exception NotReadableException using laravel 4

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

问题描述

我正在使用 laravel 4 并安装了 Intervention Image 包.当我在我的代码中使用它时 method ->resize, ->move etc etc... 我有这个 error:

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

图片来源不可读

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 ExceptionNotReadableException("Image source not readable");
            break;
    }

如果对您有帮助的话,我还在 MAC OS 上使用 MAMP 和 Sublime Text 3.

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

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

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',
);

(我没有向你展示我的视图的重定向,但它在我的控制器的这一部分工作得很好)

这是我的表单代码(使用刀片 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

当然我已经安装了Intervention Image包 按照官网image.intervention.io/getting_started/installation强>(网址).

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?

推荐答案

改变这个:

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

为此:

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

详细了解 Laravel 文档中的文件.

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

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