【发布时间】:2015-04-08 13:45:57
【问题描述】:
我的表格
{{ Form::open(array('url' => 'upfile', 'files' => 'true', 'method' => 'post', 'class' => 'form')) }}
<p>Sólo se admiten archivos en formato .pdf y no mayor a 127MB</p>
<p>
{{ Form::file('expediente', array('class' => 'text-field column_one', 'required' => 'required')) }}
</p><br>
<p>
{{ Form::text('nombrearchivo', null, array('class' => 'text-field column_one', 'required' => 'required', 'placeholder' => 'Nombre del Expediente.')) }}
</p><br>
{{ Form::hidden('username', $username) }}
<p style="color: red;">
<ul>
@foreach ($errors->all() as $message)
<li style="color:red;">{{$message}}</li>
@endforeach
<ul>
</p>
{{ Form::submit('Añadir Expediente', array('class' => 'submit submitNavy submitForm')) }}
{{ Form::close() }}
我的控制器:
public function saveExpediente(){
ini_set("memory_limit","7G");
ini_set('upload_max_filesize', '127M');
ini_set('post_max_size', '127M');
ini_set('max_input_time', 0);
ini_set('max_execution_time', 0);
set_time_limit(0);
ignore_user_abort(true);
$rules = array(
'username' => 'required|exists:users,username',
'expediente' => 'required',
'nombrearchivo' => 'required|min:5'
);
$validator = Validator::make(Input::all(), $rules);
//$fileExtension = Input::file('expediente')->guessClientExtension();
$file = Input::file('expediente');
if ($validator->fails()) {
//dd($file);
return Redirect::back()
->withErrors($validator) // send back all errors to the login form
->withInput(); // send back the input (not the password) so that we can repopulate the form
}/*else if ($fileExtension != 'pdf'){
$validator->failed();
return Redirect::to('upload')->withErrors([
'expediente' => 'El archivo debe estar en formato PDF!',
])->withInput();
}*/else {
File::makeDirectory('expedientes/'.Input::get('username'), 0770, true, true);
Input::file('expediente')->move('expedientes/'.Input::get('username'),Input::file('expediente')->getClientOriginalName());
$expediente = new Expediente;
$expediente->username = Input::get('username');
$expediente->archivo = Input::file('expediente')->getClientOriginalName();
$expediente->nombrearchivo = Input::get('nombrearchivo');
$expediente->save();
return Redirect::back()->with('message', 'Se añadió correctamente el expediente al usuario.')->with('tipo','message-success');
}
}
当我上传大于 8mb 的 laravel 返回 NULL 时,就像字段一样,它们是空的。我已经得到了变量 PHP.init 的值。我使用 Laravel 4.2 和 Apache,需要上传 25-40 mb 的文件大小。如果我尝试 dd(Input::file('expediente')) 返回 NULL
【问题讨论】:
-
您是否在 php.ini 中检查了您的最大上传文件大小?
-
还有 post_max_size 吗?
-
哦..不!它是 7MB... 现在我们确定这就是问题所在。该应用程序位于共享服务器上。我们不能在不联系公司支持的情况下更改变量值吗?
-
您不能为此使用“ini_set”。您必须联系您的托管公司。也许他们有解决方案。
标签: php apache laravel file-upload