以下代码只上传两个文件。我想将两个文件放在一个唯一的文件夹中。代码确实创建了一个随机文件夹,但是,如何将上传的文件移动到该文件夹中?
.php
<?php
$new_image_name = uniqid("IMG_",false);
$target_dir = uniqid();
mkdir("C:/xampp/htdocs/uploads/" . $target_dir);
//I just put random_dir here as a placeholder
$target_file = $random_dir . $new_image_name . basename($_FILES["fileToUpload"]["name"]);
$target_file2 = $random_dir . $new_image_name . basename($_FILES["fileToUpload2"]["name"]);
if ( $_FILES["fileToUpload"]["tmp_name"] ) move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
if ( $_FILES["fileToUpload2"]["tmp_name"] ) move_uploaded_file($_FILES["fileToUpload2"]["tmp_name"], $target_file2);
?>