Chinaunix首页 | 论坛 | 博客
  • 博客访问: 305824
  • 博文数量: 111
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 707
  • 用 户 组: 普通用户
  • 注册时间: 2013-02-26 11:00
个人简介

小伙向前冲呀,小伙向前冲呀。

文章分类

全部博文(111)

文章存档

2014年(43)

2013年(68)

我的朋友

分类: PHP

2013-11-05 07:08:20

这是一个PHP的文件上传类带图片显示的.其实做成函数就可以了.不过还是做成类好玩一点.~~~~ 
本来应该用JS来验证上传文件类型的.但懒得做了. 
代码:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
  2. <html xmlns="">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title>php 图片上传 - </title>
  6. </head>
  7. <body>
  8. <form id="form1" name="upload" enctype="multipart/form-data" method="post" action="upload.php">
  9. <input type="hidden" name="MAX_FILE_SIZE " />
  10.   <input type="file" name="file" />
  11.   <input type="submit" name="Submit" value="提交" />
  12. </form>
  13. </body>
  14. </html>
  15. <?php
  16.  Class upload
  17.  {
  18.   var $upload_name;
  19.   var $upload_tmp_address;
  20.   var $upload_server_name;
  21.   var $upload_filetype ;
  22.   var $file_type;
  23.   var $file_server_address;
  24.   var $image_w=900; //要显示图片的宽
  25.   var $image_h=350; //要显示图片的高
  26.   var $upload_file_size;
  27.   var $upload_must_size= 50000; //允许上传文件的大小,自己设置
  28.   function upload_file()
  29.   {
  30.    $this->upload_name = $_FILES["file"]["name"]; //取得上传文件名
  31.    $this->upload_filetype = $_FILES["file"]["type"];
  32.    $this->upload_server_name = date("Y_m_dH_i_s").$this->upload_name;
  33.    $this->upload_tmp_address = $_FILES["file"]["tmp_name"]; //取得临时地址
  34.    $this->file_type = array("image/gif","image/pjpeg"); //允许上传文件的类型
  35.    $this->upload_file_size = $_FILES["file"]["size"]; //上传文件的大小
  36.    if(in_array($this->upload_filetype,$this->file_type))
  37.    { if($this->upload_file_size < $this->upload_must_size)
  38.     {
  39.         echo("上传成功,谢谢支持");
  40.      $this->file_server_address = "D:\usr\www\html\upload/".$this->upload_server_name;
  41.         move_uploaded_file($this->upload_tmp_address,$this->file_server_address);//从TEMP目录移出
  42.         echo("file_server_address width=$this->image_w height=$this->image_h/>"); //显示图片


  43.      
  44.      }
  45.      else
  46.      {
  47.       echo("文件容量太大");
  48.      }
  49.    }
  50.    else
  51.    {
  52.     echo("不支持此文件类型,请重新选择");
  53.    }


  54.   }


  55.  }
  56.  $dd = new upload;
  57.  $dd->upload_file();
  58. ?>
阅读(1306) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~