Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.