Jump to content

HELP: Need to Allow the user to specify directory to upload files to with PHP


cbassett03

Recommended Posts

I'm trying to create a PHP script that will allow a person to upload a file to a directory on a website.  The directory will be specified by the viewer in the File Upload HTML file (code given below).  I am having difficulty trying to get the PHP script (also given below) to allow me to specify a folder where I would like the uploaded file to go to ("on the fly").

 

Here are the files for you guys to test and play with:

 

Here is the HTML file code:

<html>

<head>

<title>Simple file upload</title>

</head>

<body>

<form action="doupload.php" enctype="multipart/form-data" method="POST">

<input type="hidden" name="MAX_FILE_SIZE" value="10000">

<p><strng>File to upload:</strong><input type="file" name="fileupload"></p>

<p><strong>Destination:</strong><input type="text" size="30" name="destdir"></p>

<p><input type="submit" value="Upload File"></p>

</form>

</body>

</html>

 

------

 

Here is the PHP code (in a seperate file called "doupload.php"):

<?php

 

foreach($_FILES as $file_name => $file_array) {

  echo "Path: ".$file_array['tmp_name']."<br>\n";

  echo "Name: ".$file_array['name']."<br>\n";

  echo "Type: ".$file_array['type']."<br>\n";

  echo "Size: ".$file_array['size']."<br>\n";

 

  if (is_uploaded_file($file_array['tmp_name'])) {

    move_uploaded_file($file_array['tmp_name'], $file_array['name]') or die ("could not upload.\n");

    echo "File was uploaded successfully.";

  }

}

 

 

-----

 

Now, I have a textbox in the HTML file that asks the viewer to specify what directory/folder (on the server) they want the uploaded file to be stored in, but I can't seem to get it to work properly.  I removed the functionality from the PHP script for now, so the script given above does NOT attempt to store the file in any directory other than the local directory where the script and HTML file reside.  This is the functionality I WANT to add.

 

Any advice would be greatly appreciated.  I'm still fairly new at PHP (but have a great deal of knowledge in C/C++ though), so I'm picking it up fairly quickly.

 

Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.