Simple download file script. server problem

Discussion in 'PHP' started by Nesooo, Apr 4, 2012.

  1. #1
    Hi, I have problem with code below, this code I use on my wordpress site. Basically this code GET attachment ID on post page and when user click download on that page it should download file ... but it not working ... code is ok, but problem is with my server, I have tested this code on some other servers and it is working ... basically when somebody click download it show error page, file or folder not found ... I think that problem is with header.

    My server is Centos OS 6.3, WHM/Cpanel 11, PHP 5.3.6, Apache 2.2, safe_mode = of ...

    Can anybody tell me what I need to change on server to resolve this ...

    <?php
       require('wp-blog-header.php');
       $attachmentID = $_GET['id'];
       $attachmentname= $_GET['n'];
       $attachment = wp_get_attachment_url( $attachmentID , false );
       $length = strlen($attachment); 
       $characters = 3; 
       $start = $length - $characters; 
       $type = substr($attachment , $start ,$characters); 
       if ($type === "wma")
       {
           header('Content-type: audio/x-ms-wma');
       }
       else if ($type === "mp3")
       {
           header('Content-type: audio/mpeg');
       }
       header("Cache-Control: public");
       header("Content-Description: File Transfer");
       header("Content-Disposition: attachment; filename=$attachmentname");
       readfile($attachment); 
    ?>
    PHP:

     
    Nesooo, Apr 4, 2012 IP
  2. chanif.alfath

    chanif.alfath Active Member

    Messages:
    148
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    88
    #2
    hi,

    you can try take a look on your .htaccess file,
    maybe something wrong in that file..
     
    chanif.alfath, Apr 4, 2012 IP