欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

php 文件上传类 下载 自己亲自做的 有大用

shiping1 的头像

https://github.com/aivis/PHP-file-upload-class (没有使用)
http://www.verot.net/php_class_upload.htm (没有使用)
https://github.com/verot/class.upload.php (没有使用)

下面是自己亲自做的方法
需要用到 
fileupload.class.php 见附件 把后缀名 改成 php 即可
 

( 把下面的代码 复制一下为test.php 和 fileupload.class.php 放到同一目录下 运行test.php 即可测试运行!)

<?php
   //页面输出中文 
   header("Content-Type:text/html;charset=utf-8");
   //error_reporting(0);
   //使用自定义的上传类
   include "fileupload.class.php";
   //如果用户提交上传
   if(isset($_POST['dosubmit'])) {
      //创建上传类的对象
      $up = new FileUpload();
      //设置上传的类型
      $up->set("allowtype", array('jpg','jpeg', 'gif', 'png'));
      //开始上传
      if($up->upload('res')) {
         //获取上传后的名子
         $filename = $up->getFileName();    
         $filepath = dirname(__FILE__)."/uploads/".$filename;
         //形成上传的数据
         var_dump($filename);
         var_dump($filepath);
      }else{
         echo $up->getErrorMsg();
      }
   }

?>
<br>上传的多媒体文件有格式和大小限制,如下: <br>
<p>
图片(image): 1M,支持JPG格式  <br>
语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式 <br> 
视频(video):10MB,支持MP4格式 <br>
缩略图(thumb):64KB,支持JPG格式 <br>
</p>

单个图像文件上传的表单

<form action="" method="post" enctype="multipart/form-data">
   上传文件: 
   <input type="file" name="res">
   <input type="submit" name="dosubmit" value="上传">
</form>

多个图像文件上传的表单

<form action="" method="post" enctype="multipart/form-data">
上传文件: 
<input type="file" name="res[]">
<input type="file" name="res[]">
<input type="file" name="res[]">
<input type="file" name="res[]">
<input type="submit" name="dosubmit" value="上传">
</form>

 


附件大小
Plain text icon fileupload2.class.php7.89 KB
Plain text icon fileupload.class.php7.97 KB
普通分类: