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. Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.