我正在使用laravel 4,我安装了干预图像包。当我在代码中使用它时,使用方法、、->resize、->move等.我有一个错误:
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 Exception\NotReadableException("Image source not readable");
break;
}我还在MAC上使用MAMP和崇高文本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',
);(我没有向你们展示我的观点的重定向,但对我的控制器的这一部分来说,它运行得很好)
这里是我的表单代码(使用刀片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当然,我已经在官方网站image.intervention.io/getting_started/installation (url)之后安装了干预图像包。
如何使我的文件“可读性”?或解决此错误?
发布于 2014-06-12 23:55:47
改变这一点:
$file = Image::make('url_Avatar');对此:
$file = Input::file('url_Avatar');
// ...
$filename = '...';
Image::make($file->getRealPath())->resize('200','200')->save($filename);阅读更多关于file on Laravel documentation的信息。
发布于 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:发布干预/映像
配置文件中的示例内容:
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'
);发布于 2016-08-29 06:17:33
如果您在公共路径中使用子文件夹,请使用chmod更改该文件夹的权限,例如cd public; chmod -Rv 755 public/{your_path_name};。
跑
man chmod;了解更多详细信息
https://stackoverflow.com/questions/24195028
复制相似问题