用PHP實現檔案上傳

來源:互聯網
上載者:User
一、利用php的檔案函數來實現上傳
   這段代碼分為兩個檔案,一個為upload.html,一個是upload.php。
    上傳檔案選擇:upload.html 代碼如下:


       <html><head><title>上傳檔案表單</title></head>
       <body>
       <form enctype="multipart/form-data" action="upload.php" method="post">
         <input type="hidden" name="max_file_size" value="100000">
       <center>請選擇檔案:
         <input name="userfile" type="file">  
         <input type="submit" value="上傳檔案">
       </center>
       </form>
       </body>
       </html>

    *** 說明 ***
       1、請注意<form enctype="multipart/form-data"......>這是一個標籤,我們要實現檔案的上傳,必須指定為 multipart/form-data ,否則伺服器將不知道你在幹什麼!
       2、值得注意的是檔案upload.html中表單選項 MAX_FILE_SIZE 的隱藏範圍,通過設定
    其Value(值)可以限制上傳檔案的大小。
      處理剛剛上傳的檔案:upload.php 代碼如下:


         <html>
         <head>
         <title>處理上傳檔案</title>
         </head>
         <body>
         <?
         copy($userfile,"newfile");
         echo $userfile."-使用者上傳到伺服器上的檔案臨時存放的名稱<br>";
         echo $userfile_name."-在使用者機器上該檔案的原始名稱<br>";
         echo $userfile_size."-上傳檔案的實際位元組數<br>";
         echo $userfile_type."-如果使用者的瀏覽器提供了這個資訊的話,它表示mime的類型。例如image/gif<br>";
         ?>
         </body>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.