Kurrel Posted June 12, 2008 Share Posted June 12, 2008 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. Link to comment https://forums.phpfreaks.com/topic/109885-solved-downloading-csv-file-filled-with-php-code-rather-than-original-contents/ Share on other sites More sharing options...
Kurrel Posted June 13, 2008 Author Share Posted June 13, 2008 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. Link to comment https://forums.phpfreaks.com/topic/109885-solved-downloading-csv-file-filled-with-php-code-rather-than-original-contents/#findComment-564577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.