茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1675806 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
PI20101106_00005.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

PHP特區 : [轉貼]PHP上傳實例

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]PHP上傳實例
PHP上傳實例

--------------------------------------------------------------------------------

上傳檔案的網頁
<form enctype="multipart/form-data" action="__URL__" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>


接收參數陣列
檔案名稱:
$_FILES['userfile']['name']


檔案格式:
$_FILES['userfile']['type']


檔案大小:
$_FILES['userfile']['size']


檔案暫存的位置(伺服器上暫存的位置,必須要移動到正確的位置):
$_FILES['userfile']['tmp_name']


錯誤訊息:
$_FILES['userfile']['error']


語法例:
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
   echo "File is valid, and was successfully uploaded.\\\\n";
} else {
   echo "Possible file upload attack!\\\\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

?>


多檔同時傳送陣列實例:
<form action="" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="submit" value="Send" />
</p>
</form>
<?php
foreach ($_FILES["pictures"]["error"] as $key => $error) {
   if ($error == UPLOAD_ERR_OK) {
       $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
       $name = $_FILES["pictures"]["name"][$key];
       move_uploaded_file($tmp_name, "data/$name");
   }
}
?>


來源出處:PHP5網管實驗室 - PHP上傳實例
前一個主題 | 下一個主題 | | | |

討論串




Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|