Download the file corrupted. Content type not working?

I want to allow the user to upload a pdf file, the download code is below .... for some odd reason, even if the file is loading. I get an error message that the file is damaged on the server ... Can someone help me and indicate where I am making my mistake.

<php

$name = $_POST["name_first"];

    $mail = $_POST['email'];


    $number = $_POST['phone_number'];

            $email_message = "first name: {$name} email is {$mail} number is {$number} ";
            mail('fanaa@gmail.com', 'Form Response', $email_message);

                if ($mail == "" OR $name == "" OR $number == "")
                    {
                        echo "Enter valid details  ";

                    }
                    else
                    {
                        header('Content-type: application/pdf');
                        header('Content-Disposition: attachment; filename="tokina.pdf"');
                        readfile('docs/tokina.pdf');

                    }
?>
+5
source share
8 answers

I used this code to download pdf files:

header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header('Content-Type: application/octetstream');
    header("Content-Transfer-Encoding: Binary");
    header("Content-length: ".filesize($file));
    header("Content-disposition: attachment; filename=\"".basename($filename)."\"");
    readfile("$file");                
  }

This should be good, and make sure there are no spaces or return characters (best not to avoid php php).

If you find that you still have problems, open the damaged file using notepad (there may be a php error warning inside).

Hope this helps!

+13

, ? PHP - , PDF, .

+2
header('Content-type: application/pdf');

PHP php_gettext, .

+1

header('Content-type: "application/octet-stream"');

header('Content-type: application/octet-stream');
0

, . :

header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
readfile('original.pdf');
0

PDF tokina.pdf , PHP. "tokina.pdf.htm" - HTML 404 . / PDF , "" - PDF, .

, , , , readfile . , / , :

readfile('docs/tokina.pdf');

, application/pdf

0

script

   header('Content-Type: application/force-download');
   header('Content-Disposition: attachment; filename='.$filename);
   header('Content-Transfer-Encoding: binary');
   header('Content-Length: '.filesize($filenamepath));

   readfile($filenamepath);

. , UltraEdit, .

, ?> PHP .

?> - . .

, .

0

$download_path = your path (where to look for the files)
set_time_limit(0);
$file_url = $download_path . $data['link'];
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($file_url). '"');
//then to read the file
readfile($file_url);

0

All Articles