move_uploaded_file() 函數可以將上傳的文件移動到新位置。如果文件名不是有效的上傳文件,則不會發生任何操作並返回 false。如果文件名是有效的上傳文件但由於某種原因無法移動,則不會發生任何操作並返回 false。此外,可以發出警告。
用法
bool move_uploaded_file ( string $filename , string $destination )
該函數可以檢查filename 指定的文件是否是一個有效的上傳文件,也就是說它是通過PHP 的HTTP POST 上傳機製上傳的。如果文件有效,則可以將其移動到目標指定的文件名。
如果對上傳的文件所做的任何操作可能會向用戶或什至同一係統上的其他用戶顯示其內容,則特別使用這種檢查。
示例
<?php
$uploads_dir = "/PhpProject/uploads";
foreach($_FILES["pictures"]["error"] as $key => $error) {
if($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name = basename($_FILES["pictures"]["name"][$key]);
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
}
?>
相關用法
- PHP move_uploaded_file()用法及代碼示例
- PHP money_format()用法及代碼示例
- PHP metaphone()用法及代碼示例
- PHP mhash_get_hash_name()用法及代碼示例
- PHP mysqli_get_server_info()用法及代碼示例
- PHP mysqli_data_seek()用法及代碼示例
- PHP mysqli_insert_id()用法及代碼示例
- PHP mysqli_fetch_assoc()用法及代碼示例
- PHP mkdir()用法及代碼示例
- PHP mysqli_connect_error()用法及代碼示例
- PHP mhash_keygen_s2k()用法及代碼示例
- PHP microtime()用法及代碼示例
- PHP mysqli_fetch_all()用法及代碼示例
- PHP mt_rand( )用法及代碼示例
- PHP mysqli_next_result()用法及代碼示例
- PHP mysqli_stmt_affected_rows()用法及代碼示例
- PHP mime_content_type()用法及代碼示例
- PHP mysqli_begin_transaction()用法及代碼示例
- PHP mysqli_real_escape_string()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP - Function move_uploaded_file()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。