PHP圖片上傳代碼 2

來源:互聯網
上載者:User


<?php 
 Class upload 
 { 
  var $upload_name; 
  var $upload_tmp_address; 
  var $upload_server_name; 
  var $upload_filetype ; 
  var $file_type; 
  var $file_server_address; 
  var $image_w=900;  //要顯示圖片的寬 
  var $image_h=350;  //要顯示圖片的高 
  var $upload_file_size; 
  var $upload_must_size= 50000; //允許上傳檔案的大小,自己設定 
  function upload_file() 
  { 
   $this->upload_name = $_FILES["file"]["name"];    //取得上傳檔案名稱 
   $this->upload_filetype = $_FILES["file"]["type"]; 
   $this->upload_server_name = date("Y_m_dH_i_s").$this->upload_name; 
   $this->upload_tmp_address = $_FILES["file"]["tmp_name"];    //取得臨時地址 
   $this->file_type = array("image/gif","image/pjpeg");  //允許上傳檔案的類型 
   $this->upload_file_size = $_FILES["file"]["size"];  //上傳檔案的大小 
   if(in_array($this->upload_filetype,$this->file_type)) 
   { 
   
   
   if($this->upload_file_size < $this->upload_must_size) 
    { 
        echo("上傳成功,謝謝支援"); 
     $this->file_server_address = "./upload/tx/".$this->upload_server_name; 
        move_uploaded_file($this->upload_tmp_address,$this->file_server_address);//從TEMP目錄移出 
        echo("<img src=$this->file_server_address width=$this->image_w height=$this->image_h/>");  //顯示圖片 
     
     } 
     else 
     { 
      echo("檔案容量太大"); 
     } 
   } 
   else 
   { 
    echo("不支援此檔案類型,請重新選擇"); 
   } 
  }  
 } 

?>

 

 



<?php

include(''./lib/wodream/image/image_upload.php''); 
 $dd = new upload; 
 $dd->upload_file(); 

?>

 

 



<center><form  id="form1" name="upload" enctype="multipart/form-data" method="post"  action="index.php?controler=userinfo&action=image">
上傳檔案: <br><input type="hidden" name="MAX_FILE_SIZE " /> 
<input name="file" type="file"   style="width:200;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff" size="17">
<input type="submit" name="Submit"  value="上傳" style="width:30;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff" size="17"><br><br><br>
允許上傳的檔案類型為:jpg|jpeg|png|pjpeg|gif|bmp|x-png|swf <br><br>
<a href="index.php">返回</a>
</form>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.