2015-02-12 15:58:00
index.html
- <form method="POST" enctype="multipart/form-data" action="{:U('Index/upload')}">
- <tr >
- <td>flv文件</td>
- <td><input type="file" name="flv" /></td>
- </tr>
- <tr >
- <td>视频压缩文件</td>
- <td><input type="file" name="movie" /></td>
- </tr>
- <tr>
- <td>缩略图</td>
- <td><input type="file" name="img" /></td>
- </tr>
- <input type="submit" value="上传" />
- </form>
复制代码
复制代码
UploadFile.class.php 162行
- if (!is_dir($savePath)) {
- // 检查目录是否编码后的
- if (is_dir(base64_decode($savePath))) {
- $savePath = base64_decode($savePath);
- } else {
- // 尝试创建目录
- if (!mkdir($savePath)) {
- $this->error = '上传目录' . $savePath . '不存在';
- return false;
- }
- }
- } else {
- if (!is_writeable($savePath)) {
- $this->error = '上传目录' . $savePath . '不可写';
- return false;
- }
- }
复制代码
复制代码
改成
- if(!is_array($savePath)){
- if (!is_dir($savePath)) {
- // 检查目录是否编码后的
- if (is_dir(base64_decode($savePath))) {
- $savePath = base64_decode($savePath);
- } else {
- // 尝试创建目录
- if (!mkdir($savePath)) {
- $this->error = '上传目录' . $savePath . '不存在';
- return false;
- }
- }
- } else {
- if (!is_writeable($savePath)) {
- $this->error = '上传目录' . $savePath . '不可写';
- return false;
- }
- }
- }
复制代码
复制代码
UploadFile.class.php 194行
- $file['savepath'] = $savePath;
复制代码
复制代码
改成
- $file['savepath'] = is_array($savePath)?$savePath[$key]:$savePath;
复制代码
复制代码
- Public function upload() {
- import('Org.Net.UploadFile');
- $upload = new \Org\Net\UploadFile(); // 实例化上传类
- $upload->maxSize = 3145728; // 设置附件上传大小
- $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
- // $upload->savePath = './Public/Uploads/'; // 设置附件上传目录
- $upload->savePath = array('flv'=>'./Public/Uploads/flv/','movie'=>'./Public/Uploads/movie/','img'=>'./Public/Uploads/img/');
- if (!$upload->upload()) {
- $this->error($upload->getErrorMsg());
- } else {// 上传成功 获取上传文件信息
- $info = $upload->getUploadFileInfo();
- }
- }
复制代码
复制代码
$upload->savePath 改为数组
./Public/Uploads/flv/
./Public/Uploads/movie/
./Public/Uploads/img/
这3个目录要手动创建 这样在就变成不影响原来程序的
情况下实现上传多个文件到不同的目录了
更多精彩内容:各种AI课程、技能课程、黑科技软件、网站小程序源码、副业小项目、PPT模板等精品素材、电商课程、推广引流课程等,尽在 天边资源网 。