Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

downloading a file

Status
Not open for further replies.

JCrou82

Programmer
Aug 23, 2002
265
US
i want to know is there something special that i need to do to make a file download correctly from my site. I have a .dat file which is really a comma delim flat text file. if i make a link to it and just right click save target as, when i open it from my desktop, i get a square character instead of a new line. I renamed the file to have a txt extension and it still downloads weird. if i open it from FTP, i geat the line breaks instead of the squares. does anyone know how to fix this or if there is another way of doing this. Thanks
 
set the header content type:


If you want the user to be prompted to save the data you are sending, such as a generated PDF file, you can use the Content-Disposition header to supply a recommended filename and force the browser to display the save dialog.


<?php
// We'll be outputting a PDF
header(&quot;Content-type: application/pdf&quot;);

// It will be called downloaded.pdf
header(&quot;Content-Disposition: attachment; filename=downloaded.pdf&quot;);

// The PDF source is in original.pdf
readfile('original.pdf');
?>



Bastien

cat, the other other white meat
 
When you download by FTP, you are probably looking at an ASCII file transfer. Your web browser may be transferring it as a binary file. If you can name the file as CSV on the server instead of DAT, your web browser may interpret it as an ASCII text file.

Different text encodings define new line breaks differently (\n or \r). You need to find a way to transfer the file as ASCII - - or try to redefine how line breaks are created in the file on the server.

- - picklefish - -
 
...or you can try to redefine how your web browser expects to receive the file, by defining the content, as Bastien noted.

scrap what I posted earlier. I explained what the problem was, but Bastien gave the right solution.



- - picklefish - -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top