【发布时间】:2014-05-21 03:24:14
【问题描述】:
大家好:我这里有个问题!我正在使用 laravel 框架做我的项目。当我尝试验证输入文件时遇到问题。我做了一个简单的网站来测试同样的问题。这是我的路线:
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 文件并按下按钮时,我得到了一个错误:
警告:64859333 字节的 POST 内容长度超过了 Unknown on line 0 中 8388608 字节的限制
它不应该跨越验证规则!这是为什么?任何人都可以帮助我吗? ps:对不起,如果我的英语很糟糕:D
非常感谢大家。有用!!!但现在新的问题来了。当人们选择比“post_max_size”更大的文件时,我们无法控制他们。哈哈
【问题讨论】:
标签: php validation file-upload laravel-4