關於上傳檔案的疑惑
最近在聽php視頻,其中有一個代碼不理解
if (is_uploaded_file($_FILES['upfile']['tmp_name'])){
$upfile=$_FILES["upfile"];
}
主要是取值的問題,比如說upfile我知道是從表單取的值,但是tmp_name我就不知道怎麼取到的值,還請大牛們指教,謝謝!
分享到:
------解決方案--------------------
$_FILES 是一個全域數組,儲存了檔案上傳的一些資訊
第一個參數是表單的 input name,第二個下標可以是 "name", "type", "size", "tmp_name" 或 "error"。就像這樣:
$_FILES["file"]["name"] - 被上傳檔案的名稱
$_FILES["file"]["type"] - 被上傳檔案的類型
$_FILES["file"]["size"] - 被上傳檔案的大小,以位元組計
$_FILES["file"]["tmp_name"] - 儲存在伺服器的檔案的臨時副本的名稱
$_FILES["file"]["error"] - 由檔案上傳導致的錯誤碼
------解決方案--------------------
這要什麼大牛指教啊,連我這個學php不到2個月的都知道了。
看php基礎的教程都有說了。
The entries in $_FILES will be stored with the name of the tag from your
HTML form.Your form element is named userfile, so the array will have the following
contents:
n The value stored in $_FILES[‘userfile’][‘tmp_name’] is the place where the
file has been temporarily stored on the web server.
n The value stored in $_FILES[‘userfile’][‘name’] is the file’s name on the
user’s system.
n The value stored in $_FILES[‘userfile’][‘size’] is the size of the file in bytes.
n The value stored in $_FILES[‘userfile’][‘type’] is the MIME type of the
file―for example, text/plain or image/gif.
n The value stored in $_FILES[‘userfile’][‘error’] will give you any error
codes associated with the file upload.This functionality was added at PHP 4.2.0.
------解決方案--------------------
tmp_name,那是個隨機的檔案名稱