Home  >  Article  >  Backend Development  >  PHP AjaxForm submits image upload and displays image

PHP AjaxForm submits image upload and displays image

墨辰丷
墨辰丷Original
2018-05-30 10:18:261314browse

This article mainly introduces PHP AjaxForm to submit image upload and display image source code in detail. It has certain reference value. Interested friends can refer to

PHP dofile.php file upload source code.

$file_allow_size){  
  $data['status'] = 1;
  $data['msg'] = "文件大小超过限制,只能上传".sizeFormat($file_allow_size)."的文件!"; 
  } 
  if($data['status']==1){
  $data['status'] = 1;
  $data['msg'] = $data['msg'];
  exit(json_encode($data)); 
  }
  if($data['status']==0){
  if(file_exists($file_upload)){   
   $file_new_name = date("YmdHis").'_'.rand(10000,99999).'.'.$file_ext;
   $file_save_path = $file_upload.$file_new_name; 
   $data['status'] = 0;  
   $data['url'] = $file_save_path;
   move_uploaded_file($file_tmp_name,$file_save_path);
   exit(json_encode($data));    
  }else{
   exit(json_encode($data));
  }  

  }   
 }
}

function sizeFormat($size)
{
 $sizeStr='';
 if($size<1024)
 {
  return $size."bytes";
 }
 else if($size<(1024*1024))
 {
  $size=round($size/1024,1);
  return $size."KB";
 }
 else if($size<(1024*1024*1024))
 {
  $size=round($size/(1024*1024),1);
  return $size."MB";
 }
 else
 {
  $size=round($size/(1024*1024*1024),1);
  return $size."GB";
 } 
}



?>

The HTML is as follows




The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

How to implement a mortgage calculator in PHP

##phpThe file contains the directory configuration open_basedir usage and performance

##php Implement the method of calling ffmpeg to obtain video information

The above is the detailed content of PHP AjaxForm submits image upload and displays image. 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