help in unique download link code

Discussion in 'PHP' started by money4leads, Sep 9, 2008.

  1. #1
    hello

    i have a peoblem , i am trying to make a unique download link for my website visitors, but i have a problem that when I click the download link it show a strange characters page instead of showing the download box.

    i tried to download a jpg image file and didn't work, I am new in php coding and need your help what I missed here.

    here is the code
    
    ob_start();
       $mm_type="application/force-download";
       $file = "images/1.jpg";
       $filename = "image1.jpg";
       
       header('Cache-Control: public, must-revalidate');
       header("Pragma: hack");
       header("Content-Description: File Transfer");
       header("Content-Type: " . $mm_type);
       header("Content-Length: " .(string)(filesize($file)) );
       header('Content-Disposition: attachment; filename="'.$filename.'"');
       header("Content-Transfer-Encoding: binary\n");
    
       ob_end_clean();
       readfile($file);
    
    PHP:
    the real file is the $file i.e "images/1.jpg"

    and the other one "image1.jpg" is what the visitor's file will actually be called when he/she saves it.

    thaks for any help.
     
    money4leads, Sep 9, 2008 IP
  2. human

    human Peon

    Messages:
    38
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Somethink like that :

    <?PHP
    ob_start();
    function readfile($file){
       $mm_type="application/force-download";
       $filename = "image1.jpg";
       header('Cache-Control: public, must-revalidate');
       header("Pragma: hack");
       header("Content-Description: File Transfer");
       header("Content-Type: " . $mm_type);
       header("Content-Length: " .(string)(filesize($file)) );
       header('Content-Disposition: attachment; filename="'.$filename.'"');
       header("Content-Transfer-Encoding: binary\n");
    }
    
       ob_end_clean();
    $file = "images/1.jpg";
       readfile($file);
    ?>
    PHP:
     
    human, Sep 10, 2008 IP