博客
关于我
php教程--案例29(文件上传类)
阅读量:314 次
发布时间:2019-03-03

本文共 1468 字,大约阅读时间需要 4 分钟。

t218.php

'文件过大,超过了php配置的限制', 2=>'文件过大,超过了form表单的限制', 3=>'文件没有上传完毕', 4=>'文件没有上传', 6=>'没有找到临时上传目录', 7=>'临时文件写入失败', ); $this->error = isset($upload_errors[$file['error']])?$upload_errors[$file['error']]:'未知错误'; return false; } //类型不符 if(!in_array($file['type'],$this->allow_types)) { $this->error = '此类型不能上传,允许的类型为:'.implode('|',$this->allow_types); return false; } //文件过大 if($file['size'] > $this->max_size) { $this->error = '文件不能超过'.$this->max_size.'字节'; return false; } //生成一个随机id+扩展名 $new_file = uniqid($prefix).strrchr($file['name'],'.'); //子目录 $sub_path = date('YmdH'); //全路径 $upload_path = $this->upload_path.$sub_path; //判断不是目录时,建立目录 if(!is_dir($upload_path)) { mkdir($upload_path); if(move_uploaded_file($file['tmp_name'],$upload_path.'/'.$new_file)) { return $sub_path.'/'.$new_file; } else { $this->error = '移动失败'; return false; } } } public function getError() { return $this->error; }}

t219.php

up($_FILES['pic'],'user_'))) { echo $up_load1->getError(); }}?>
测试上传文件类

编辑用户头像

用户名:小明

现有头像:

上传头像:

 

转载地址:http://pvem.baihongyu.com/

你可能感兴趣的文章
multi swiper bug solution
查看>>
MySQL Binlog 日志监听与 Spring 集成实战
查看>>
MySQL binlog三种模式
查看>>
multi-angle cosine and sines
查看>>
Mysql Can't connect to MySQL server
查看>>
mysql case when 乱码_Mysql CASE WHEN 用法
查看>>
Multicast1
查看>>
mysql client library_MySQL数据库之zabbix3.x安装出现“configure: error: Not found mysqlclient library”的解决办法...
查看>>
MySQL Cluster 7.0.36 发布
查看>>
Multimodal Unsupervised Image-to-Image Translation多通道无监督图像翻译
查看>>
MySQL Cluster与MGR集群实战
查看>>
multipart/form-data与application/octet-stream的区别、application/x-www-form-urlencoded
查看>>
mysql cmake 报错,MySQL云服务器应用及cmake报错解决办法
查看>>
Multiple websites on single instance of IIS
查看>>
mysql CONCAT()函数拼接有NULL
查看>>
multiprocessing.Manager 嵌套共享对象不适用于队列
查看>>
multiprocessing.pool.map 和带有两个参数的函数
查看>>
MYSQL CONCAT函数
查看>>
multiprocessing.Pool:map_async 和 imap 有什么区别?
查看>>
MySQL Connector/Net 句柄泄露
查看>>