我正在研究一个使用PHP上传文件的简单方法 我的表格:
<form action="upload.php" enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input type="file" name="file_upload">
<input type="submit" name="submit" value="Upload">
</form>
和PHP:
$id = '3';
if (isset($_POST['submit'])) {
$tmp_file = $_FILES['file_upload']['tmp_name'];
$file = basename($_FILES['file_upload']['name']);
$upload_dir = "uploads";
if (file_exists($upload_dir."/".$file)) {
die("File {$file} already exists in {$upload_dir} folder.");
}
if(move_uploaded_file($tmp_file, $upload_dir."/".$file)) {
$message = "File " . $file . " uploaded to " . $upload_dir;
echo $message;
} else {
# Code with message about error.
}
}
文件仅在uploads
文件夹中成功上传。在该uploads
文件夹中,我有其他几个文件夹:1
,2
,3
等等。
我的问题:如何在上传后移动特定子文件夹中的文件? (子文件夹名称 - 来自变量id
。)谢谢!