Jump to content

Select Upload Destination


Xeven

Recommended Posts

I have a small question to ask about using PHP.  I am fairly new to it and have only been using it for about five months now.

 

I have already been able to make a drop down list with information located on a mysql database.

 

The second thing which I am unsure is even possible is using this in conjunction with uploading a file.  So I have looked around and understand (just about) how to make a file upload page using php.  But I am looking to add a drop down function so you can select where to upload the file to, but this drop down list needs to contain information from the mysql databse again.

 

Am I thinking stupidly and this is not possible?  Or can it be done?

 

Thanks

Link to comment
Share on other sites

Sure it can be done.

 

1) store all the possible file destinations in the database

2) extract them and put them into a <select> list in your upload form

 

Before I explain the next step, you have to understand how files work when you upload them. You upload them and they get put in a temporary directory. Once the whole file has been successfully uploaded, it is moved from the temp directory into the directory you specify

 

3) use the information you gathered in step 2 to build the path name to the file where the file should be stored

4) use this path name in your script to tell the file where to be saved.

Link to comment
Share on other sites

Good news, you are thinking creatively, not stupidly!

 

As for your question:

Do you know the basic PHP file upload script? If No, please understand it from w3schools.com or tizag.com

 

Once you have got the basic upload script ready do as below for the front-end form:

1. Create a database table to contain names of various folders.

2. Run a query to fetch all the folder names and put them in an array(//Lets name the array as $folderList).

<select name="uploadFolderName">
<?php
foreach($folderList as $folderName)
{
echo "<option>$foldername</option>";
}
?>
</select>

 

Once the form is ready, you have to do some changes in the back-end PHP script

<?php
//the variable target path is the name of the folder to which the file is uploaded.
$target_path=$_POST['uploadFolderName'];
?>

 

Note: Since an HTML form is easy to manipulate, you should check that the selected folder is available using IF ELSE statements.

 

Hope you could understand!

Link to comment
Share on other sites

Ah cool, thanks guys.  I'm happy that it is possible to do as it would be a great help to me.  I have looked at the w3chools stuff and have been using their tutorial to help put my upload page together.

 

As for using IF ELSE statements, I have never been too confident with them.  I just find them a bit confusing really.

 

Ill give both of you guys advice a go and see how I do.

 

Thanks again.

Link to comment
Share on other sites

Ok so I have played around a bit and have managed to get a page where it can input a file into my database. 

 

Rohan you said before I would need to make some changes in the back end PHP, I am just wondering where would I put that exactly? As I am using a query to insert the data into a location I am not too sure how I would use what you have said above.

 

$query = "INSERT INTO upload (name, type, size, content, user ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$user')";

mysql_query($query) or die('Error, query failed'); 

echo "<br>File $fileName uploaded<br>";
} 
?>

 

 

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.