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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving file from server to client side - Automatically 1

Status
Not open for further replies.

bobrivers2003

Technical User
Oct 28, 2005
96
GB
I have a php script that exports all the structure and data from a mysql db, the file is saved on the server, as it is a back up of the server db I wish to download it to a client when the back up file is created.

I have tried using

Header("Content-type: application/msword");
Header("Content-Disposition: attachment; filename=backup.txt");
echo "CONTENTS OF FILE ON SERVER";

I need to open the server file, loop through each line and print to backup.txt


Does anyone have any pointers on how this can be achieved?

Many Thanks

 
When you said
I need to open the server file, loop through each line and print to backup.txt
you were pretty close.

But it seems to me that the correct operations would be open the file, loop through each line and stream that line to the browser using print.

You're right on target. This will entail use of fopen(), fgets() and a while loop.

There is example code on the PHP online manual pages to which I have provided links.



Want the best answers? Ask the best questions! TANSTAAFL!
 
If you need to do a (serverside) copy of your file, why not use ... copy()

Code:
<?php
$server_file = 'serverfile.txt';
$backup_file = 'backup.txt';
if (!copy($server_file, $backup_file)) {
   echo "failed to copy $server_file...\n";
}
?>

Regards


Jakob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top