php $_FILES詳解$_FILES

來源:互聯網
上載者:User
php $_FILES詳解$_FILES
經由 HTTP POST 檔案上傳而提交至指令碼的變數。類似於舊數組 $HTTP_POST_FILES 數組(依然有效,但反對使用)。詳細資料請參閱 POST 方法上傳。

$_FILES數組內容如下:

<input type="file" name="userfile">

$_FILES['userfile']['name']

用戶端機器檔案的原名稱。

$_FILES['userfile']['type']
檔案的 MIME 類型,需要瀏覽器提供該資訊的支援,例如“image/gif”。

$_FILES['userfile']['size']
已上傳檔案的大小,單位為位元組。

$_FILES['userfile']['tmp_name']
檔案被上傳後在服務端儲存的臨時檔案名稱。

$_FILES['userfile']['error']
和該檔案上傳相關的錯誤碼。['error'] 是在 PHP 4.2.0 版本中增加的。
注: 在 PHP 4.1.0 版本以前該數組的名稱為 $HTTP_POST_FILES,它並不像 $_FILES 一樣是自動全域變數。PHP 3 不支援 $HTTP_POST_FILES 數組。
move_uploaded_file -- 將上傳的檔案移動到新位置
說明
bool move_uploaded_file ( string filename, string destination )


本函數檢查並確保由 filename 指定的檔案是合法的上傳檔案(即通過 PHP 的 HTTP POST 上傳機制所上傳的)。如果檔案合法,則將其移動為由 destination 指定的檔案。

如果 filename 不是合法的上傳檔案,不會出現任何操作,move_uploaded_file() 將返回 FALSE。

如果 filename 是合法的上傳檔案,但出於某些原因無法移動,不會出現任何操作,move_uploaded_file() 將返回 FALSE。此外還會發出一條警告。

這種檢查顯得格外重要,如果上傳的檔案有可能會造成對使用者或本系統的其他使用者顯示其內容的話


PHP單檔案上傳

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>單檔案上傳</title><style type="text/css"><!--body,td,th {font-size: 12px;}body {margin-left: 10px;margin-top: 10px;margin-right: 10px;margin-bottom: 10px;}--> </style></head><body><form action="" method="post" enctype="multipart/form-data" name="form"><input name="up_file" type="file" /><input type="submit" name="submit" value="上傳" /></form><?phpif(!empty($_FILES[up_file][name])){$fileinfo = $_FILES[up_file];if($fileinfo['size'] < 1000000 && $fileinfo['size'] > 0){   move_uploaded_file($fileinfo['tmp_name'],$fileinfo['name']);   echo '上傳成功';}else{   echo '檔案太大或未知';}}?></body></html>

php, $_FILES詳解, $_FILES php $_FILES詳解$_FILES

  • 聯繫我們

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