SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Download links

  1. #1
    SitePoint Evangelist hantaah's Avatar
    Join Date
    Jul 2011
    Location
    Birmingham, Uk
    Posts
    562
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Download links

    I'm trying to create a professional looking system for clients to download files from. I've create a download button with the link:

    Download PDF

    I'd like it to just present the client with a save now, view now box, however I'm getting a long loading pdf viewer. How do i get away from this or how is it done properly?

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Location
    Florida
    Posts
    58
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You will need to manipulate the header content type in order to tell the browser you want the file to be downloaded instead of viewed. If you are using PHP have a look here to get you pointed in the right direction.

    http://stackoverflow.com/questions/1...file-using-php

  3. #3
    SitePoint Evangelist hantaah's Avatar
    Join Date
    Jul 2011
    Location
    Birmingham, Uk
    Posts
    562
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    @JamesKenny ; thanks for this info.

    so I created a file called attached.php and put this code inside it

    Code:
        $fp = @fopen($yourfile, 'rb');
    
        if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
    {
    	header('Content-Type: "application/octet-stream"');
    	header('Content-Disposition: attachment; filename="yourname.file"');
    	header('Expires: 0');
    	header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    	header("Content-Transfer-Encoding: binary");
    	header('Pragma: public');
    	header("Content-Length: ".filesize($yourfile));
    }
    else
    {
    	header('Content-Type: "application/octet-stream"');
    	header('Content-Disposition: attachment; filename="yourname.file"');
    	header("Content-Transfer-Encoding: binary");
    	header('Expires: 0');
    	header('Pragma: no-cache');
    	header("Content-Length: ".filesize($yourfile));
    }
    
    fpassthru($fp);
    fclose($fp);
    So where then or how should I place the download link?
    many thanks

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Location
    Florida
    Posts
    58
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    you would make sure "$yourfile" is the location of the file and then link to the attached.php. The file should stream to the browser. After you get it working I would also play with some of the settings so you have a better idea of what is going on there

  5. #5
    SitePoint Evangelist hantaah's Avatar
    Join Date
    Jul 2011
    Location
    Birmingham, Uk
    Posts
    562
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    just want to say thanks for your help. I sorted it and here is the download page:

    Download page

    Much appreciated


Bookmarks

Posting Permissions

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