php上传图片 方法

时间:2019-02-24 09:08:27
【文件属性】:
文件名称:php上传图片 方法
文件大小:2KB
文件格式:ZIP
更新时间:2019-02-24 09:08:27
php 异步上传 图片 public function pic_url($m_type,$m_url,$username=''){ if(!file_exists('./'.$m_url)) { mkdir($m_url); } $img_path = empty($username)?$m_url:$m_url.$username.'/'; if($username){ if(!file_exists('./'.$img_path)){ mkdir($img_path); } }else{ $date = date('Ymd'); $path = './'.$m_url; if(!file_exists($path.$date)){ mkdir($path.$date); } $img_path = $m_url.$date.'/'; } $picname = $_FILES[$m_type]['name']; $picsize = $_FILES[$m_type]['size']; if(is_array($picname)&&is_array($picsize)) { $arr = array(); foreach($picname as $key=>&$val) { $pics = ""; if ($val != "") { $type = strstr($val,'.'); if(!$type) { $type = ".jpg"; } $pics = md5(uniqid()).$type; $pic_path = $img_path. $pics; move_uploaded_file($_FILES[$m_type]['tmp_name'][$key], $pic_path); } if($val) { $arr[] = $img_path.$pics; } } return $arr; } else { $pics = ""; if ($picname != "") { $type = strstr($picname, '.'); if(!$type) { $type = ".jpg"; } $pics = md5(uniqid()).$type; $pic_path = $img_path. $pics; move_uploaded_file($_FILES[$m_type]['tmp_name'], $pic_path); } $avatar_url = ""; if($picname) { $avatar_url = $img_path.$pics; } return $avatar_url; } }
【文件预览】:
ajax异步上传图片.php

网友评论