Downloading Files with PHP

These Things Will Help You Avoid Issues When Using PHP to Download Files

  • Make sure all your PHP files do not have empty lines after the closing PHP tag  ( ?>)
    • This rule includes the case where JAVASCRIPT or JQuery is placed inline with PHP code.  There should not be an empty line between the closing PHP tag (?>) and the opening JAVASCRIPT tag (<SCRIPT…> )
  • Don’t issue any echos other than the ones necessary to handle the bitstream generated by fread
    • This is because echo statements writes to the same buffer as PHP statements such as the following:
      • echo “Content-Disposition: filename=\””.$path_parts[“basename”].”\””;:
  • If you call SQL Server stored procedures, make sure there are not Print statements in the stored procedure.   Unconsumed print statements can cause writes to the same buffers that are used by the data streams for file downloads.
  • If your download script causes SQL Server triggers to fire, the same rule about Print statements applies:   Make sure no triggers have print statements.

Leave a Reply