www.webdeveloper.com
Results 1 to 7 of 7

Thread: [RESOLVED] Downloading

Hybrid View

  1. #1
    Join Date
    Mar 2008
    Posts
    88

    resolved [RESOLVED] Downloading

    Hey Everyone,

    I've been creating a few pages that allow users to upload the own work / images / docs etc which works fine but.... I want them to be able to view their uploads and have the option to download them again if they wanted.

    I've experimented with putting links in and but it just brings up the directory.

    Code:
    $image_viewer = "SELECT * FROM files WHERE username='$_SESSION[username]'";
    
    $show_image = mysql_query($image_viewer);
    PHP Code:
    echo "<a href='uploads/$info'>";

    while(
    $info mysql_fetch_array($show_image))

        {
        
        
        
        echo 
    $info['filename'] . " " $info['name']; echo "<br/>";
      echo 
    "<br>";



    }
     echo 
    "</a>"
    The above just brings up a list of files.

    This is just an experiment for my own knowledge but I would like to get it working so all help is appreciated!!
    Last edited by swl7; 07-10-2013 at 10:00 AM.

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    718
    Yes - the above would just give you a list of files. What did you want it to do? Display each and every type of file you are accepting? If so you would have had to upload the type of file you received so that you know how to send it back to them and set your page header appropriately when you do.

  3. #3
    Join Date
    Jul 2013
    Posts
    29
    Code:
    while (...) {
       echo "<a href=\"/uploads/{$file['name']}\">{$file['name']}</a><br />";
    }

  4. #4
    Join Date
    Jul 2013
    Posts
    29
    Well, in your case it would be $info['filename'] instead of $file['name']

    The idea is that you should print HTML code for link on each iteration, not just once before the loop.

  5. #5
    Join Date
    Mar 2008
    Posts
    88
    Brilliant that worked!

    Thanks for your help and the explanation!

    One question though: .doc and .pdf documents download straight away but the images open up in the browser. Is there a way of making them download the same as the .pdf etc?

    Thanks again

  6. #6
    Join Date
    Jul 2013
    Posts
    29
    There is the way, but doing it solely by means of php is totally wrong, because you will have to pass each file through a script.

    The correct way to do this is to tell your webserver to send certain files with specified content-type. In apache, AFAIS, it can be done with ForceType directive, which can be applied to folder or to location or to files by mask. In general you may add the following code to your .htaccess:
    Code:
    <Files ~ "\.(gif|jpe?g|png)$">
        ForceType application/octet-stream
    </Files>
    If it does not work as intended you will have to ask in apache section of this forum how to apply it properly to your setup.

  7. #7
    Join Date
    Mar 2008
    Posts
    88
    I tried the code and it half works some jpegs download while JPG doesn't and PNG doesn't so I will try on the apache section like you said.

    Thanks for all the help i'll mark this as resolved!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles