【发布时间】:2014-08-03 09:44:11
【问题描述】:
我正在使用 laravel 4 并安装了 Intervention Image 包。当我在我的代码中使用它时 method ->resize, ->move etc etc... 我有这个 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 Exception\NotReadableException("Image source not readable");
break;
}
如果对您有帮助的话,我还在 MAC OS 上使用 MAMP 和 Sublime Text 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
当然我已经安装了Intervention Image包 按照官网image.intervention.io/getting_started/installation强>(网址)。
如何使我的文件“可读”?或解决此错误?
【问题讨论】:
-
显示您的代码并确保您的图像在服务器上的位置是
readable/writable。 -
@WereWolf-TheAlpha 我已经编辑了我的代码。如何使我的图像位置
readable/writable? -
你检查答案了吗?
-
@WereWolf-TheAlpha 我检查了你的答案。这部分解决了我的问题。我已经更新了作曲家,并完成了我的代码,并注意提出您的建议。检查我对您的回答的评论。
标签: php image file-upload laravel laravel-4