標籤: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>