Home  >  Article  >  Backend Development  >  How to achieve refresh-free upload by combining php template with js upload plug-in

How to achieve refresh-free upload by combining php template with js upload plug-in

墨辰丷
墨辰丷Original
2018-06-08 09:38:361464browse

This article mainly introduces the method of combining php template and js upload plug-in to achieve refresh-free upload. Friends who are interested can refer to it. I hope it will be helpful to everyone.

Template file code:



 
  
  
  
  
 

Controller code:

public function uploads(){
  $arr = array( "errorcode"=>"1","errormsg"=>"上传成功!");
  $model = M('applicant');
  if (!empty($_FILES)) {
    //图片上传设置
    $config = array( 
    'maxSize' => 1000000, 
    'rootPath' => 'Public',
    'savePath' => '/Uploads/', 
    'saveName' => array('uniqid',''), 
    'exts'  => array('jpg', 'gif', 'png', 'jpeg'), 
    'autoSub' => false, 
    'subName' => array('date','Ymd'),
   );
   $upload = new \Think\Upload($config);// 实例化上传类
  $info = $upload->upload();
   if($info){
    $arr['errorcode'] = "0";
   } else {
    $arr["errorcode"] = "1";
    $arr["errormsg"] = $upload->getError();
   }
   /* 返回JSON数据 */
   $this->ajaxReturn($arr);
  }
}

Summary: The above is the entire content of this article, I hope it can be helpful to everyone Learning helps.

Related recommendations:

PHP View the background, process and solution of the current variable type

php is based on Imagick implements the function of adding watermarks and text to images

php implements the function of the judges' scorer

The above is the detailed content of How to achieve refresh-free upload by combining php template with js upload plug-in. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn