这是我的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()
我查看了文件的内容,但数组为空.
解决方法:
我使用此功能上传图片,并且效果很好-
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;
}
}
标签:laravel,laravel-5-2,php 来源: https://codeday.me/bug/20191118/2030616.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。