skip to Main Content

Could someone help me with a little PHP problem?

This is my code:

$mr = mysqli_fetch_assoc($ms);
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename="" . basename($mr['flink']) . """); 
readfile($mr['flink']);
header("Location: ref.php?action=viewdeti&id=".$_GET['id']);

Where $mysqli is my mysql connection and $id is $_GET[‘id’].

$mr[‘flink’] is link to file hosted on my server.

Now the problem:

When the code is hosted on my server the code runs successful and allow to download the file from localhost and redirect me to correct page.

When the code is hosted on web server hosting and when run the script don’t download the file hosted on the web server but opens the file in browser as code and doesn’t redirect me.

I will attach photos to see the problem in fact.

The versions on server’s apache, mysql, php is same as on the localhost.

The files for downloading are *.pdf

Please if you have any idea, help me.

Thanks in advance.

Best Regards,
Rossen

WEB SERVER
LOCALHOST

2

Answers


  1. Chosen as BEST ANSWER

    Now already working properly. I recompile it via UTF8 without B

    header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($mr['flink'])) . ' GMT'); 
    header('Content-Length: ' . filesize($mr['flink']));
    

    And now it's ok.

    Thanks all for help.


  2. $mr = mysqli_fetch_assoc($ms);
    
    header('Content-Transfer-Encoding: binary');  // mainly for Gecko browsers
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($mr['flink'])) . ' GMT');   // modified date of file, useful with caching 
    header('Accept-Ranges: bytes');  // To resume download
    header('Content-Length: ' . filesize($mr['flink']));  // file size
    header('Content-Encoding: none');    // don't worry about encoding
    header('Content-Type: application/pdf');  // mime type if the file is PDF, change if required
    header('Content-Disposition: attachment; filename=' . basename($mr['flink']));  // force browser to show the Save As dialog
    readfile($mr['flink']);  // actually download the file, required
    header("Location: ref.php?action=viewdeti&id=".$_GET['id']);    // copied from question
    

    Each line has comment which is explained.

    Along with the above, make sure that the actual file has .pdf extension. It somehow appears that the file is missing the extension on your remote server.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search