SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    download data corrupt

    Hi all

    I have following script to download pdf and docs ... i want to make sure it forces a download and doesn't open in the same window!!!

    The problem is that the pdf's can't be opent .... when I open them directly from the server there is no problem!!!

    the script:

    PHP Code:
    $filesize=filesize($root.$relative_url);
     
     
    header('Cache-Control: private'); 
        
    header('Pragma: private'); 
     
    header('Content-Type: application/force-download'); 
        
    header('Content-Type: application/octet-stream'); 
        
    header('Content-Type: application/download'); 
     
    header("Content-Disposition: attachment; filename=$name");
     
    header('Content-Transfer-Encoding: binary'); 
        
    header("Content-Length: ".$filesize); 
     
     
    $fp fopen($$root.$relative_url,"r");
     echo 
    fread($fp,$filesize);
     
    fclose($fp);
     exit; 
    any thoughts???

    Thanks

    Peanuts
    the neigbours (free) WIFI makes it just a little more fun

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $fp = fopen($$root.$relative_url,"r"); should be
    $fp = fopen($root.$relative_url,"r"); ?

    Also take a look at http://php.net/readfile instead of doing the filesize(), fopen() thing.

  3. #3
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Mark,

    I tried Readfile same error ... and the extra $ is a typo
    the neigbours (free) WIFI makes it just a little more fun

  4. #4

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Which data would $root and $relative_url have?

  5. #5
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, strange, the following works ok for me :
    PHP Code:
    <?php
    $file 
    'test.pdf';
    header('Cache-Control: private');
    header('Pragma: private');
    header('Content-Type: application/force-download');
    header('Content-Type: application/octet-stream');
    header('Content-Type: application/download');
    header("Content-Disposition: attachment; filename=test.pdf");
    header('Content-Transfer-Encoding: binary');
    readfile($file);
    ?>

  6. #6
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Weird ... I copied your stuff .... changed $file = to point to my file location ...

    And Presto chango ... It works ..

    Thanks ... I don't know why it wasn't working but ... hey if it's working now I'm happy
    the neigbours (free) WIFI makes it just a little more fun


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
  •