Jump to content

[SOLVED] Downloading CSV file filled with PHP code rather than original contents.


Kurrel

Recommended Posts

Hi PHPers,

 

I've written code that allows a user to input the location of a csv file.  My code then takes the CSV file, reads the contents and adds some additional fields calculated from several contained fields.

 

$source							= $_FILES["filesource"];

		$sourcehandle			= fopen($source["tmp_name"], "rb+");
		$destination			= FIRSTBASE."/calculator/masscalcs/";
		$destname					= "updated ".$source["name"];
		$desthandle				= fopen($destination.$destname, "w");

		$count						= 0;

		while (!feof($sourcehandle)) {
                              // Math stuff and lots of fwriting
		}

		fclose($sourcehandle);
		fclose($desthandle);

 

This file is created on the server side fine.

 

The problem comes in trying to download the darn thing back to the user's machine.  So far I can get a file named correctly but filled with php code, from the previous page so far as I am aware.

 

This has been accomplished with :


		header("Content-type: text/x-csv");
		header("Content-Disposition: attachment; filename=\"".$destname."\"");
		header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
		header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past

 

I've tried a couple of variations on this, including form downloads but the results have varied between the php-spam in the file to an empty file simply named 'updated', no extension and no contents.

 

Help?  ???

 

Kurrel,

- All smiles.

Problem resolved by creating a download function, not using any of the includes in my main program, that was called by the href.  I suspect a header problem with text being passed before the header but I can't find it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.