pdf - PHP force download, not sending full binary files -


i'm creating protected file download system e-commerce website. using php authenticate user logged in , owns product before downloaded. using example provided php.net manual have run error serving both pdf , png files.

it has worked @ 1 point, during development. we've gone live, seems have broke... fortunately website not running full-force @ moment it's not huge issue right now.

what happening:

you visit download url. verified owner of product, , download starts. appears normal, reviewing headers looks ok. header states content length "229542" (224.16kb), looks ok.

the problem:

when download completes, file size 222 bytes. there no errors displayed, , no php errors/warnings/notices being sent in file or browser. it's if php being terminated, without warnings. if turn debugging on, don't see warnings.

the source file looks this (in notepad++, it's pdf it's binary)

when downloaded, looks this (only 7 lines, compared 2554)

my guess:

i issue header related. maybe caused plugin? shows in chrome's networking console:

enter image description here

response headers:

below response headers. "connection: close" concerns me. not sending header. i'm guessing sent exit command.

access-control-allow-origin:* cache-control:must-revalidate, post-check=0, pre-check=0 connection:close  content-description:file transfer content-disposition:attachment; filename="workbook.pdf" content-length:229542 content-transfer-encoding:binary content-type:application/pdf date:tue, 03 sep 2013 21:16:14 gmt expires:0 pragma:public server:apache x-powered-by:plesklin 

i have tried:

  1. turning on php debugging sort of error/warning, don't useful in browser or in downloaded file source.

  2. outputting browser, rather streaming. file still cut short, expect pdf try display in browser's pdf reader - doesn't try. white page bunch of unknown symbols.

  3. using +rb read mode, using fopen( $file['file'], 'rb' ); echo fread( $fh, filesize( $file['file'] ) ); fclose( $fh );

  4. using ignore_user_abort(true) , set_time_limit(0) no effect (also tried set_time_limit(10000) in case, still nothing)

  5. sending .txt file. this worked. tried simple 5-byte text file, , again 86.3kb file. both appear have come out same went in. must related binary files...


/* --- $file variable looks like: $file = array(   [file] => /var/www/vhosts/my-website/uploads/workbook.pdf   [type] => application/pdf   [filesize] => 229542   [filename] => workbook.pdf   [upload_date] => 1377278303 ); */  // stream file user if (file_exists($file['file'])) {   header_remove(); // remove set header   header('content-description: file transfer');   header('content-type: ' . $file['type']);   header('content-disposition: attachment; filename="'.$filename.'"');   header('content-transfer-encoding: binary');   header('expires: 0');   header('cache-control: must-revalidate, post-check=0, pre-check=0');   header('pragma: public');   header('content-length: ' . $filesize);   ob_clean();   flush();   readfile($file['file']);   exit; } 

i know older thread have solution here.

you have script somewhere in application that's compressing spaces or other characters.

ob_start("sanitize_output"); 

that problem in 1 scenario noticed. if turn off buffer reduction script (called "sanitize_output" above) .pdf show normally. 2kb's noticed trimmed spacing or cutting out unneeded characters.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -