Possible Duplicate:
How do I allow users to chose where to upload the file?
I want to allow my users to chose where to upload their files. If anyone could help me, that’d be great.
uploader.html
http://pastebin.com/LQP9jxLH
<div id="main">
<center><h2>File Uploader Beta</h2></center><br />
<center>
<form action="upload.php" method="post" enctype="multipart/form-data">
File: <input type="file" name="filename" />
<input type="submit" value="Upload" />
</form>
</center>
</div>
upload.php
http://pastebin.com/CtM1LW13
$folder = "files/";
$HTTP_POST_FILES = "";
if(isset($_FILES['filename']['tmp_name'])) // Check if $_FILES['filename']['tmp_name'] is there
{
if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
if (move_uploaded_file($_FILES['filename']['tmp_name'], $folder.$_FILES['filename']['name'])) {
Echo "Your file has been uploaded! You should probably tell Cody what you uploaded so he can get it in the right place. :)";
} else {
Echo "Haha! You don't have access to do that.";
}
} else {
Echo "Your upload has failed.";
}
}
All help is appreciated. 🙂
Also, I need it to generate a script into the page once the file has uploaded.
Say, if example.jpg was uploaded to /Cody/Pictures.
It would delete
No files were found..
and replace it with:
File Name: $FileName
Download:
Can anyone do that? Thanks if you can!
I only do this because you seem to be so young:
I would add a field containing the upload path called
path(as its name attribute) into your upload form, the upload path can simply be typed in or chosen using a folder selector: You could iterate through the top level of your upload directory ($folder) using the PHP-functionscandir($files=scandir($folder);). This delivers a list of all files and folders in$folder. (Let’s assume, it contains the folderfooand the fileindex.html). At this point you iterate the list ($files) delivered by thescandir-function and check if the current item is a directory usingis_dir.If so, you can generate a dynamic hyperlink, which executes a dynamic JavaScript function. For the top level of you would receive exactly one link like:
Of course you need to define the function getFolderContents which is a JavaScript function that delivers the folder contents of its parameter using JSON or Ajax.
As this request is sent to
/getFolderContents.phpyou need to create this PHP-file and simply copy the functionlistFiles(as you can see above) in there and just execute the following code:I haven’t tested it, only quickly written and of course you have adapt it to your needs. And there are still some options missing like, moving one directory up again or so, because this script won’t allow you to get back.
Best regards from Germany.