Php 干预\Image\Exception\NotReadableException使用laravel 4
我使用的是laravel 4,我安装了干预图像软件包。当我在我的代码中使用方法时,->调整大小、->移动等。。。我有一个错误:Php 干预\Image\Exception\NotReadableException使用laravel 4,php,image,file-upload,laravel,laravel-4,Php,Image,File Upload,Laravel,Laravel 4,我使用的是laravel 4,我安装了干预图像软件包。当我在我的代码中使用方法时,->调整大小、->移动等。。。我有一个错误: Intervention \ Image \ Exception \ NotReadableException public function upload() { //***** UPLOAD FILE (on server it's an image but an Url in Database *****// // get the input file $f
Intervention \ Image \ Exception \ NotReadableException
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',
);
@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
图像源不可读
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 OS上的MAMP和Sublime Text 3对您有帮助,我也在使用。
这是我在控制器中的代码:
Intervention \ Image \ Exception \ NotReadableException
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',
);
@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
(我不向您显示我的视图的重定向,但它在我的控制器的这一部分工作得很好)
这是我的表单代码(使用blade laravel模板):
Intervention \ Image \ Exception \ NotReadableException
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',
);
@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
@extends('layout.default')
@章节(“标题”)
我的项目名称-EditProfile
@停止
@节(“内容”)
{{Form::open(数组('url'=>'uploadAvatar','files'=>true))}
{{Form::label('pseudo','pseudo(*):')}
{{Form::text('pseudo',Input::old('nom'))}
@如果($errors->has('pseudo'))
{{$errors->first('pseudo')}
@恩迪夫
{{Form::label('url_Avatar','Avatar:')}
{{Form::file('url\u Avatar',Input::old('url\u Avatar'))}
@如果($errors->has('url\u Avatar'))
{{$errors->first('url\u Avatar')}
@恩迪夫
{{Form::submit('Validate your avatar')}
{{Form::close()}}
@停止
当然,我已经在官方网站Image.Intervention.io/getting_start/installation(url)之后安装了干预图像包
如何使文件可读?或解决此错误 改变这一点:
$file = Image::make('url_Avatar');
为此:
$file = Input::file('url_Avatar');
// ...
$filename = '...';
Image::make($file->getRealPath())->resize('200','200')->save($filename);
阅读更多信息。如果在公用路径中使用子文件夹,请使用chmod更改该文件夹的权限 例如
cd-public;
chmod-rv755 public/{您的路径名}代码>
跑
有关此解决方案的更多详细信息
$filename = str_slug($products->name)."-0.jpg";
$filename_fb = 'fb-'.$filename;
$filename_tw = 'tw-'.$filename;
$img = Image::make($_FILES['photo']['tmp_name']);
// resize image
$img->resize(800, 400);
// save image
$img->save($path.'/'.$filename);
我也有同样的问题。当我更改图像驱动程序时,一切正常
尝试将图像驱动程序从app/config/packages/intervention/image/config.php从GD更改为Imagick
如果找不到配置文件,请尝试运行以下命令:
在Laravel 5中发布配置
$php artisan供应商:发布--provider=“干预\Image\ImageServiceProviderLaravel5”
在Laravel 4中发布配置
$php artisan配置:发布干预/图像
配置文件中的示例内容:
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'
);
显示您的代码,并确保您在服务器上的图像位置是可读/写的。
@WereWolf TheAlpha我已经编辑了我的代码。我如何使我的图像位置可读写?你检查了答案吗?@狼人TheAlpha我检查了你的答案。这部分解决了我的问题。我已经做了一个composer更新,我最终完成了我的代码,并仔细考虑了您的建议。检查我对你答案的评论。事实上,我将你建议我的行改为$file=Input::file('url_Avatar')代码>。我还更改了行$file=Image::make($Image->getRealPath())->resize('200','200')->save('upload/')。$filename)编码>到Image::make($file->getRealPath())->调整大小('200','200')->保存($filename)代码>。它工作得很好。谢谢你的帮助,你的回答引导我做了这个功能。我有一个类似的问题。我也像你指出的那样编辑了我的代码,但它仍然给我同样的错误信息。你能帮我看看吗?我也有同样的问题。我需要从url图像。使用Input::file()我们只能从输入类型文件生成图像。但在我的例子中,输入是url。那我怎么办呢?你试过了吗http://someurl.com/image.png')->save('/path/ImageName.png')代码>?