将文件上传到动态目录

时间:2014-09-24 15:12:16

标签: php html

我有一个将文件上传到目录的表单。

html和php是吼叫。

问题是php的第3行(我认为)。它不会使它从下拉列表中获取目录。如果我将其更改为$ output_dir =“uploads”;它将创建uploads目录并将文件放在那里。

HTML:

  <form id="myForm" action="upload.php" method="post" enctype="multipart/form-data">
<center>
  <input type="file" id="upload" name="myfile" class="custom-file-input">
</center>
<br>
<select name="folder">
            <option value="Test1">Our Photos</option>
            <option value="StockPhoto">Stock Photos</option>
            <option value="Video">Videos</option>
            <option value="Document">Documents</option>
            <option value="Other">Other</option>
        </select>
<br>
<br />
<input type="submit" value="Upload" />
<br>
<br>
<div id="progress">
  <div id="bar"></div>
  <div id="percent">0%</div >
</div>

  </form>

PHP:

<?php
//upload.php
$output_dir = $_POST['folder'];

if(isset($_FILES["myfile"]))
{
    //Filter the file types , if you want.
    if ($_FILES["myfile"]["error"] > 0)
    {
      echo "Error: " . $_FILES["file"]["error"] . "<br>";
    }
    else
    {
        //move the uploaded file to uploads folder;
        move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir. $_FILES["myfile"]["name"]);

     echo "Uploaded File :".$_FILES["myfile"]["name"] .$output_dir;
    }

}
?>

0 个答案:

没有答案