Question:
When you use the move_uploaded_file
function, can you keep the name that was created in the tmp_name
? or must you always change the name to something else?
If you can keep the name of the file that you are moving as the tmp_name, how must you pass in the argument? I tried the following code, and I can't seem to get it to work.
Please see the code below:
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];
}
}
When I pass the second argument in as $upload_dir."/".$target_file , there doesn't seem to be any issues, but when I pass it as $upload_dir."/".$tmp_file as shown in the codes above, it keeps giving me the following error:
SCREAM: Error suppression ignored for
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