Route::get('test','TestController@uploadFile');
Route::post('test','TestController@uploadFile');
这是我的控制人员:
class TestController extends Controller{
public function uploadFile(){
return View::make('test');
}
public function pUploadFile(){
try {
$file=Input::file('file');
$validator=Validator::make(array('file' => $file ),array('file' =>'image|mimes:jpeg,jpg,png,gif|max:3072'));
if($validator->fails()){
return View::make('test')->withErrors($validator);
}
$destinationPath = "uploads";
$extension =$file->getClientOriginalExtension();
$filename='testfile'.$extension;
$upload_success = $file->move($destinationPath, $filename);
if($upload_success)
return 'succeeded';
return 'failed';
} catch (Exception $e) {
return $e;
}
}
}
这是我的blade.php文件:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="container">
<form method="post" action="{{Asset('test')}}" id="form-register" enctype="multipart/form-data">
<h2>Choose an image</h2>
<input type="file" name="file" id="file"/>
{{$errors->first('file')}}
<button>Upload</btn>
</form>
</div>
</body>
</html>
当我选择大小为66mb的swf文件并按下按钮时,出现错误:
警告:POST内容长度为64859333字节超过第0行未知的8388608字节限制
它不应该越过验证规则!这是为什么?任何人都可以帮助我吗? ps:对不起,如果我的英语太糟糕了:D
非常感谢你们所有人。有用!!!但现在新问题已经来临。我们无法在选择大型文件时控制人员,而不是“post_max_size&#39;”。洛尔
答案 0 :(得分:0)
您的PHP配置仅允许上传最多8MB。调整php.ini中的post_max_size
和upload_max_filesize
。
upload_max_filesize = 128M
post_max_size = 128M
答案 1 :(得分:0)
它不是验证规则问题,它与你在那里的设置有关。
确保将php.ini中的post_max_size和max_file_uploads更新为更大的值。
max_file_uploads = 256 post_max_size = 256
您可以使用phpinfo()函数找到php.ini文件的位置。
http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize
post_max_size integer
设置允许的帖子数据的最大大小。此设置也 影响文件上传。要上传大文件,此值必须更大 比upload_max_filesize。如果配置启用了内存限制 脚本,memory_limit也会影响文件上传。一般来说, memory_limit应大于post_max_size。当一个整数是 使用时,该值以字节为单位。简写符号,如上所述 在这个FAQ中,也可以使用。如果发布数据的大小更大 比post_max_size,$ _POST和$ _FILES超全局都是空的。 这可以以各种方式跟踪,例如,通过$ _GET 变量到处理数据的脚本,即,然后检查是否 $ _GET ['processed']已设置。
max_file_uploads integer
允许同时上传的最大文件数。 从PHP 5.3.4开始,上传字段在提交时留空 计入此限制。