问题:
当您使用该move_uploaded_file
功能时,您可以保留在 中创建的名称tmp_name
吗?还是必须始终将名称更改为其他名称?
如果您可以将要移动的文件的名称保留为 tmp_name,那么您必须如何传入参数?我尝试了以下代码,但似乎无法正常工作。
请看下面的代码:
if(isset($_POST['submit'])){
$tmp_file = $_FILES['file_upload']['tmp_name'];
$target_file = basename($_FILES['file_upload']['name']);
$upload_dir = "uploads";
if(move_uploaded_file($tmp_file, $upload_dir."/".$tmp_file)){
$message = "File uploaded successfully.";
}else{
$error = $_FILES['file_upload']['error'];
$message = $upload_errors[$error];
}
}
当我将第二个参数作为$upload_dir."/".$target_file传递时,似乎没有任何问题,但是当我将它作为$upload_dir."/".$tmp_file 传递时,如上面的代码所示,它不断给我以下错误:
SCREAM:忽略错误抑制
Warning: move_uploaded_file(uploads/C:\wamp\tmp\php1EA0.tmp): failed to open stream: Invalid argument in C:\wamp\www\bb2\uploads.php on line 26