干预图像异常 NotReadableException使用laravel 4

Intervention Image Exception NotReadableException using laravel 4(干预图像异常 NotReadableException使用laravel 4)
本文介绍了干预图像异常 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)