我laravel 4(最后更新)工作,我创建了一个形式在那里我们可以上传图片(标志/头像)。我对MAC OS,我用崇高的文本3,laravel和MAMP应用。我所有的配置都设置正确,没有任何问题。RuntimeException的SplFileInfo ::的getSize():统计失败... Laravel 4上传图片
我probleme是,当我从我的形式提交到达场我有这个错误:的RuntimeException SplFileInfo ::的getSize():统计失败/应用程序/ MAMP的/ tmp/PHP/phpRUJfMX
下面是从我的形式nameOfTheForm.blade.php代码:
@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
下面是从我控制器的代码:
public function uploadAvatar() {
//*****UPLOAD FILE (on server it's an image, on the DB it's an url*****
$file = Input::File('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();
$uploaded = Input::File('url_Avatar')->move($destinationPath,$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',
);
上传的文件代码工作正常,我将文件注册到所需的选定文件夹中。我对我的路线没有任何问题(不需要显示这部分代码)。
但是当我提交表单,我有这样的错误: 的RuntimeException SplFileInfo ::的getSize():统计失败/应用程序/ MAMP的/ tmp/PHP/phpRUJfMX
错误信息的详细内容: 开:/Applications/MAMP/htdocs/nameOfMyProject/vendor/laravel/framework/src/Illuminate/Validation/Validator.php
}
elseif (is_array($value))
{
return count($value);
}
elseif ($value instanceof File)
{
return $value->getSize()/1024;
}
else
看来,这Laravel需要(stat - 给出文件的信息),也就是说,需要从上传的文件,这里的大小有信息,但我尝试这在我的控制器只其中,这里的$上传,我移动的文件在我选择的文件夹中前行:
//I add this line code before
$size= $file->getSize();
$uploaded=Input::File('url_Avatar')->move($destinationPath,$filename);
但是,当我这样做,我有另外一个错误:验证并不R ** ecognize文件作为图像**请求我上传有效格式。我想我需要纠正我的第一个错误(SplFileInfo :: getSize())
如果您有任何想法...谢谢。
我现在没有我的代码,但明天我会尝试这个解决方案。感谢你们两位的理解。 –
,所以它的工作原理,MAMP在htdocs文件夹中有另一个php.ini文件,我可以更改一些参数,如图像大小文件。所以我按照你的步骤,用你的代码。 –
http://php.net/manual/en/ini.core.php#ini.post-max-size - 跟进Ryan的评论 – hoopyfrood