这是我的upload.blade.php代码
{!!Form::open(array('url'=>'parser','method'=>'POST','enctype'=>'multipart/form-data','onsubmit'=>'return validate(this)', 'files'=>true)) !!}
<div class="panel panel-default file-upload">
<div class="panel-heading">
<label for="exampleInputFile">Upload Manually :</label>
</div>
<div class="panel-body">
{!! Form::file('Filename') !!}
<progress id="progressBar" value="0" max="100" width="100%">
</progress>
<h3 id="status"></h3>
<p id="loaded_n_total"></p>
{!! Form::submit('Submit', array('class'=>'btn btn-info','value'=>'Upload File')) !!}
{!! Form::close() !!}
然后我有一个控制器类来移动上传的文件,上传功能是
public function uploadFile(){
$a=session('upload');
$path="/logparser/html/upload/".$a;
$fileExistsFlag = 0;
$file = array('Filename' => Request::file('Filename'));
if(!(is_dir($path))){
mkdir($path, 0777);
chmod($path,0777);
}
Request::file('Filename')->move($path);
Session::flash('success', 'Upload successfully');
return view('dash');
}
它给出了一个错误:在null上调用成员函数move() 我查看了文件的内容,但数组是空的。
答案 0 :(得分:2)
我使用此功能上传图片并且工作正常 -
public function upload_image(){
$input = Input::instance();
$destinationPath = public_path("uploads/user");
if($input->file('user_image')){
try{
if ($input->file('user_image')->isValid())
{
$extension = $input->file('user_image')->getClientOriginalExtension();
$fileName = rand(11111, 99999) . '.' . $extension;
if($input->file('user_image')->move($destinationPath, $fileName)){
// Updating user image in db
}else{
$this->data['message'] = Lang::get('messages.image_upload_fail');
$this->utilObj->renderJson('error', $this->data);
}
}else{
$this->data['message'] = Lang::get('messages.image_upload_fail');
$this->utilObj->renderJson('error', $this->data);
}
}
catch (\Exception $e) {
Log::error("AppUsers::upload_image() " . $e->getMessage());
$this->data['message'] = Lang::get('messages.image_upload_fail');
$this->utilObj->renderJson('error', $this->data);
return false;
}
}else{
$this->data['message'] = Lang::get('messages.image_required');
$this->utilObj->renderJson('error', $this->data);
return false;
}
}
答案 1 :(得分:1)
只需更改php.ini文件即可解决问题。 我更改了&#34; upload_max_filesize = -1&#34;和&#34; post_max_size = -1&#34;。
答案 2 :(得分:0)
这应该有效
$file=Input::file('Filename')->getClientOriginalName();
Input::file('Filename')->move($destination,$file);
答案 3 :(得分:0)
你可以写这样的代码
public function uploadFile(Illuminate\Http\Request $request){
$a=session('upload');
$path="/logparser/html/upload/".$a;
$fileExistsFlag = 0;
if(!(is_dir($path))){
mkdir($path, 0777);
chmod($path,0777);
}
$request->file('Filename')->move($path);
Session::flash('success', 'Upload successfully');
return view('dash');
}
有关更多信息,您可以阅读laravel 5.2的文档 https://laravel.com/docs/5.2/requests#files