Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8225567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:27:28+00:00 2026-06-07T15:27:28+00:00

Possible Duplicate: How do I allow users to chose where to upload the file?

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:27:30+00:00Added an answer on June 7, 2026 at 3:27 pm

    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-function scandir ($files=scandir($folder);). This delivers a list of all files and folders in $folder. (Let’s assume, it contains the folder foo and the file index.html). At this point you iterate the list ($files) delivered by the scandir-function and check if the current item is a directory using is_dir.

    function listFiles($directory)
    {
        $files=scandir($directory);
        for($i=0; $i < count($files); $i++)
        {
            if(is_dir($files[$i]) && file_exists($files[$i]))
            {
                echo '<a href="javascript:getFolderContents('.json_encode($files[$i]).');">'.htmlentities($files[$i]).'</a>';
            }
        }
    }
    echo '<div id="uploadcontainer">';
    listFiles($folder); //you must have declared $folder
    echo '</div>';
    

    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:

    <a href="javascript:getFolderContents('foo');">foo</a>`
    

    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.

    function getFolderContents(folder)
    {
        Request=new XMLHttpRequest();
        Request.open("GET", "/getFolderContents.php?folder="+encodeURIComponent(folder), true);
        Request.onreadystatechange=function()
        {
            if(Request.readyState==4 && Request.status==200) //succeeded
            {
                document.getElementsByName("path")[0].value=folder+"/";
                document.getElementById("uploadcontainer").innerHTML=Request.responseText;
            }
        }
        Request.send(null);
    }
    

    As this request is sent to /getFolderContents.php you need to create this PHP-file and simply copy the function listFiles (as you can see above) in there and just execute the following code:

    listFiles($_GET["folder"]);
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I only allow certain filetypes on upload in php? i'm
Possible Duplicate: python: how to encrypt a file? I'm trying to make application that
Possible Duplicate: Allow access permission to write in Program Files of Windows 7 okay,
Possible Duplicate: How to hide text field in Html File Upload I'm setting up
Possible Duplicate: 'Like' a page using facebook graph api I want to let users
Possible Duplicate: Jquery trigger file input I'm working on a form which allows users
Possible Duplicate: Allow php sessions to carry over to subdomains How to setup user
Possible Duplicate: HTML Text Input allow only Numeric input I used this script function
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How to do the vector of sets in C++? I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.