Hi!
I am a newbie in PHP and I have a problem.
I have a file upload script. In the form one can choose a path (you can choose it from a drop-down menu). But I don't have no idea hot to post it to the PHP file.
It's the form.

<form action="upload.php" method="post"
enctype="multipart/form-data"><br>
<label for="file">File:</label>
<input type="file" name="file" id="file" /> 
    <br>
    Path: <select name="path" value="path">
<?php  
foreach(glob('/a/directory/goes/here/*', GLOB_ONLYDIR) as $dir) 
{ 
    $dir = basename($dir); 
    echo '<option value="', $dir, '">', $dir, '</option>'; 
}  
?>

        </select><br>
<input type="submit" name="submit" value="Submit" />
</form>

It's the PHP code (upload.php):

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
&& ($_FILES["file"]["size"] < 5120000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Name: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp.: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("/a/directory/goes/here/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "/a/directory/goes/here/" . $_FILES["file"]["name"]);
      echo "Saved: " . "" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Error";
  }
?>
</body>
</html>

Basically, you can see from the first code that the upload directory can me chosen among directories which are located in "/a/directory/goes/here/". But I would like to know if one chooses "travelling" (from drop-down menu) for example, how the file can be uploaded to "/a/directory/goes/here/travelling". At the moment it's uploaded to "/a/directory/goes/here/". And the script and upload destination are not in the same directory!

PS: There might be some errors in the scripts as I changed a bit at the moment.

I forgot to delete those lines in the last code!

</body>
</html>

I got it to work by myself! So no help needed anymore!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.