simcoweb Posted July 19, 2006 Share Posted July 19, 2006 We're writing this file:[code]$data = "";$result = mysql_query("SHOW COLUMNS FROM `iplog`") or die(mysql_error());while($row = mysql_fetch_array($result)) { $data .= $row[0].",";}$data = substr($data,0,-1)."\r\n";$result = mysql_query("SELECT * FROM `iplog`") or die(mysql_error());while($row = mysql_fetch_assoc($result)) { foreach($row as $r) { $data .= "$r,"; } $data = substr($data,0,-1)."\r\n";}$handle = fopen("data.csv","wb");fwrite($handle,$data);fclose($handle);[/code]Which works great in creating the CSV file. However, we'd like to make this newly generated file downloadable. As it stands right now all i've been able to do is have it display the CSV file and the person would need to copy and paste it. Sorta lame i'd say. So, what I would like it to do is either:1) write/create the file AND turn it into a downloadable zip file, or2) write/create the file AND have another 'option' to download it which would then turn it into a zip file (so instead of write/zip at once it's two different functions). With scenario #2 the person could then decide if they want to copy and paste or zip and download.Ideas? Link to comment https://forums.phpfreaks.com/topic/14993-how-can-i-write-this-file-turn-it-into-a-downloadable-zip-file-at-same-time/ Share on other sites More sharing options...
hitman6003 Posted July 19, 2006 Share Posted July 19, 2006 As far as zipping the file you may want to use a script like this:http://www.phpclasses.org/browse/package/2088.htmlOffering the file for a download is as easy as changing the headers to send the file rather than display it:[code] header("Content-length: $size");header("Content-type: $type");header("Content-Disposition: attachment; filename=$name");echo $content;[/code]Where size, type, name, and contents should be fairly obvious. Link to comment https://forums.phpfreaks.com/topic/14993-how-can-i-write-this-file-turn-it-into-a-downloadable-zip-file-at-same-time/#findComment-60256 Share on other sites More sharing options...
simcoweb Posted July 19, 2006 Author Share Posted July 19, 2006 That class file was a snap and worked exactly as I needed. Thanks for pointing me to that great resource. That's definitely a class file that can be used a LOT. Link to comment https://forums.phpfreaks.com/topic/14993-how-can-i-write-this-file-turn-it-into-a-downloadable-zip-file-at-same-time/#findComment-60324 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.