php -- 檔案上傳下載

來源:互聯網
上載者:User

標籤:style   class   blog   c   code   java   

----- 026-upload.php -----

 1 <!DOCTYPE html> 2 <html> 3 <head> 4     <meta http-equiv="content-type" content="text/html; charset=utf-8"> 5     <title>上傳圖片</title> 6 </head> 7 <body align="left"> 8 <h2>上傳圖片</h2> 9 <p style="font-size: 16pt">10 <form method="POST"enctype="multipart/form-data" style="border:1px solid; width:400px" >11     上傳圖片:<input type="file" name=‘file‘ id="file"><br/>12     放在這裡:<input type="text" name="txt"><br/>13     <input type="submit" name="upload" value="開始上傳">14 </form>15 <?php16     foreach ($_POST as $key => $value) {17         echo $key, "=>", $value, "<br/>";18     }19     if(isset($_POST["upload"])){20         echo "就緒了啊!!<br/>";21         echo $_FILES[‘file‘][‘type‘];22         if($_FILES[‘file‘][‘type‘] == "image/pjpeg")23         {24             echo "檔案名稱:", $_FILES[‘file‘][‘name‘], "<br/>";25             echo "檔案類型:", $_FILES[‘file‘][‘type‘], "<br/>";26             echo "檔案大小:", $_FILES[‘file‘][‘size‘], "<br/>";27             echo "副本名稱:", $_FILES[‘file‘][‘tmp_name‘], "<br/>";28             move_uploaded_file($_FILES[‘file‘][‘tmp_name‘], "uploads/".$_FILES[‘file‘][‘name‘]);29             echo "檔案儲存在:",  "uploads/".$_FILES[‘file‘][‘name‘], "<br/>";30             echo "<img src=", "uploads/".$_FILES[‘file‘][‘name‘], " width=300>";31 32         }33     }34 ?>35 </p>36 </body>37 </html>

----- 027-download.php -----

 1 <!DOCTYPE html> 2 <html> 3 <head> 4     <meta http-equiv="content-type" content="text/html; charset=utf-8"> 5     <title>下載檔案</title> 6 </head> 7 <body> 8 <fieldset> 9 <legend>檔案下載</legend>10 <img src="bietaichang.jpg" height="200")/>11 <a href="?action=download">下載檔案到本地<br/></a>12 <?php13     $file_name = "bietaichang.jpg";14     $file_dir = "uploads/";15     echo "檔案大小:", filesize($file_dir.$file_name), "\n";16     if(isset($_GET["action"]))17     {18         $file = fopen($file_dir.$file_name, "rb");19         header("Content-Type: application/octet-stream");20         header("Accept-Ranges: bytes");21         header("Accept-Length: ".filesize($file_dir.$file_name));22         header("Content-Disposition: attachment; filename=".$file_name);23         echo fread($file, filesize($file_dir.$file_name));24         fclose($file);25         exit;26     }27 ?>28 </fieldset>29 </body>30 </html>

聯繫我們

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