如何将文件上传到特定的子目录

时间:2015-09-10 12:07:00

标签: php forms

我正在研究一个使用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文件夹中,我有其他几个文件夹:123等等。

我的问题:如何在上传后移动特定子文件夹中的文件? (子文件夹名称 - 来自变量id。)谢谢!

0 个答案:

没有答案