php 无刷新 接受文件
- function upload_pic($path){
- $filename = 'userfile';
- $pic_path = '';
- $picname = $_FILES[$filename]['name'];
- $picsize = $_FILES[$filename]['size'];
- if ($picname != "") {
- $type = strstr($picname,'.');
- if ($type!='.jpg'&&$type!='.gif'&&$type!='.png')
- {
- $array = array(
- 'name' => '格式错误,请上传jpg,gif,png',
- 'pic' => '',
- 'size' => '',
- 'pic_path' => ''
- );
- return json_encode($array);
- }
- $pics = md5(uniqid()). $type;
- $path = $this->create_dir($path);
- $pic_path = strtr($path,array('./'=>'')). $pics;
- move_uploaded_file($_FILES[$filename]['tmp_name'], $pic_path);
- }
- if(file_exists($pic_path))
- {
- $this->process_pic($pic_path);
- }
- $size= round($picsize/1024,2);
- $arr = array(
- 'name' => $picname,
- 'pic' => $pic_path,
- 'size' => $size,
- 'pic_path' => $pic_path
- );
- return json_encode($arr);
- }
复制代码
|