首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用laravel 4干预\图像\异常\ NotReadableException

使用laravel 4干预\图像\异常\ NotReadableException
EN

Stack Overflow用户
提问于 2014-06-12 22:43:42
回答 4查看 34.9K关注 0票数 9

我正在使用laravel 4,我安装了干预图像包。当我在代码中使用它时,使用方法、、->resize、->move等.我有一个错误:

代码语言:javascript
复制
Intervention \ Image \ Exception \ NotReadableException

图像源不可读

代码语言:javascript
复制
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;
    }

我还在MAC上使用MAMP和崇高文本3,如果可以的话。

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

代码语言:javascript
复制
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模板):

代码语言:javascript
复制
@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

当然,我已经在官方网站image.intervention.io/getting_started/installation (url)之后安装了干预图像包

如何使我的文件“可读性”?或解决此错误?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2014-06-12 23:55:47

改变这一点:

代码语言:javascript
复制
$file = Image::make('url_Avatar');

对此:

代码语言:javascript
复制
$file = Input::file('url_Avatar');
// ...
$filename = '...';
Image::make($file->getRealPath())->resize('200','200')->save($filename);

阅读更多关于file on Laravel documentation的信息。

票数 15
EN

Stack Overflow用户

发布于 2017-07-04 09:25:02

我也有同样的问题。当我改变图像驱动程序时,一切都很好。

尝试将图像驱动程序从app/config/packages/intervention/image/config.php从GD更改为Imagick

如果找不到配置文件,请尝试运行以下命令:

在Laravel 5中发布配置

$ php手工供应商:发布--provider="Intervention\Image\ImageServiceProviderLaravel5“

在Laravel 4中发布配置

$ php artisan config:发布干预/映像

配置文件中的示例内容:

代码语言:javascript
复制
return array(

    /*
    |--------------------------------------------------------------------------
    | Image Driver
    |--------------------------------------------------------------------------
    |
    | Intervention Image supports "GD Library" and "Imagick" to process images
    | internally. You may choose one of them according to your PHP
    | configuration. By default PHP's "GD Library" implementation is used.
    |
    | Supported: "gd", "imagick"
    |
    */

    'driver' => 'imagick'

);
票数 1
EN

Stack Overflow用户

发布于 2016-08-29 06:17:33

如果您在公共路径中使用子文件夹,请使用chmod更改该文件夹的权限,例如cd public; chmod -Rv 755 public/{your_path_name};

代码语言:javascript
复制
man chmod;

了解更多详细信息

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24195028

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档