Maison  >  Article  >  développement back-end  >  无刷新上传图片

无刷新上传图片

WBOY
WBOYoriginal
2016-07-25 08:44:02934parcourir
php 无刷新 接受文件
                   
            
  1.         function upload_pic($path){
  2.                 $filename         = 'userfile';
  3.                 $pic_path   = '';
  4.                 $picname          = $_FILES[$filename]['name'];
  5.         $picsize          = $_FILES[$filename]['size'];
  6.         if ($picname != "") {
  7.             $type = strstr($picname,'.');
  8.             if ($type!='.jpg'&&$type!='.gif'&&$type!='.png')
  9.             {
  10.                     $array = array(
  11.                                                     'name'     => '格式错误,请上传jpg,gif,png',
  12.                                                     'pic'      => '',
  13.                                                     'size'     => '',
  14.                                                     'pic_path' => ''
  15.                                               );
  16.                 return json_encode($array);
  17.             }
  18.             $pics        = md5(uniqid()). $type;
  19.                         $path        = $this->create_dir($path);
  20.             $pic_path    = strtr($path,array('./'=>'')). $pics;
  21.             move_uploaded_file($_FILES[$filename]['tmp_name'], $pic_path);
  22.         }
  23.         if(file_exists($pic_path))
  24.         {
  25.                 $this->process_pic($pic_path);
  26.         }
  27.         $size= round($picsize/1024,2);
  28.         $arr = array(
  29.                             'name'     => $picname,
  30.                             'pic'      => $pic_path,
  31.                             'size'     => $size,
  32.                             'pic_path' => $pic_path
  33.                                 );
  34.         return json_encode($arr);
  35.         }
复制代码
上传图片


Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn