Html form + file upload from my server - how to?

Discussion in 'PHP' started by monumentplayer, Oct 17, 2009.

  1. #1
    Hello,

    I have that code (index.html):

    <input type="file" name="file">
    Code (markup):
    by which I select file from my PC (to upload). I don't want select file from my PC but I want upload file from my server (for example file.exe). How to do it?

    Folder Structure Example:
    /public_html/
    -index.html
    -file.exe
     
    monumentplayer, Oct 17, 2009 IP
  2. ThomasTwen

    ThomasTwen Peon

    Messages:
    113
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That's gonna be a little more difficult than your code...

    1) Generate a list of all available files on your server. Using PHP seems good.
    <?
    
    //define the path as relative
    $path = "/home/yoursite/public_html/whatever";
    
    //using the opendir function
    $dir_handle = @opendir($path) or die("Unable to open $path");
    
    echo "Directory Listing of $path<br/>";
    
    //running the while loop
    while ($file = readdir($dir_handle)) 
    {
       echo "<a href='$file'>$file</a><br/>";
    }
    
    //closing the directory
    closedir($dir_handle);
    
    ?> 
    
    Code (markup):
    2) Have the user select one file. I'd recommend radio buttons, but this will get terribly messy with more than 10 files, so you should think of something else, depending on your site design and purpose.
    3) Submit the file name to a PHP script, which does stuff with the file.
     
    ThomasTwen, Oct 17, 2009 IP