Irap Posted January 24, 2010 Share Posted January 24, 2010 I'm not new to php, but I have a few questions about this. I want to provide a file that is generated from a database which will contain various information. I also want the file to have a fixed filename and extension if possible. However, I want each visitor to be able to get their own unique file by specifying which information is stored in the file. So writing the file may not be the best option, because when one person writes their file the file is globally changed and any other downloaders at the time will have their file changed. The things I want to know are... 1. How can this be done so each visitor generates a unique file? 2. Is this a wise thing to allow? How much server load would be added? 3. Can I make it at least "look" like the file is coming from the same directory each time? I've already managed to create a simple version of this, where whenever I click a link, the file updates from the database. Quote Link to comment https://forums.phpfreaks.com/topic/189628-generating-files-for-visitors/ Share on other sites More sharing options...
Irap Posted January 24, 2010 Author Share Posted January 24, 2010 Heh, this always happens. I always end up asking questions no one else knows the answer to, lol. Still, if anyone can point me in the right direction as soon as possible, I'll be very grateful. Quote Link to comment https://forums.phpfreaks.com/topic/189628-generating-files-for-visitors/#findComment-1000894 Share on other sites More sharing options...
PHP Monkeh Posted January 24, 2010 Share Posted January 24, 2010 I think we need a little more information to be able to help you, as the purpose doesn't seem apparent. For example, what information will the file contain? Do you want a text file, CVS, PDF etc? Is the information stored in the file pulled from a database? Does the file need storing anywhere? Giving us the reason and purpose behind the problem will go a long way. Quote Link to comment https://forums.phpfreaks.com/topic/189628-generating-files-for-visitors/#findComment-1000901 Share on other sites More sharing options...
Irap Posted January 24, 2010 Author Share Posted January 24, 2010 I think we need a little more information to be able to help you, as the purpose doesn't seem apparent. For example, what information will the file contain? Do you want a text file, CVS, PDF etc? Is the information stored in the file pulled from a database? Does the file need storing anywhere? Giving us the reason and purpose behind the problem will go a long way. I've already stated that I want it pulled from the database. The file does not need storing, in fact I want to ensure that the file is unique to the downloader, giving him the ability to choose what information is stored in the file. What I forgot to mention was that it was a text file, an .ini file to be exact. So for example, phpMyAdmin gives you the ability to choose which database and table to export and has a few other options for exporting as a .sql file, which is basically a text file. I want to do something similar to this, generating this file without storing it anywhere. I also want to know if this would be much of a load on my server per, say 100 downloaders, the text file is only 1kb max, so I shouldn't think so. Hope you understand what I mean now. Quote Link to comment https://forums.phpfreaks.com/topic/189628-generating-files-for-visitors/#findComment-1000911 Share on other sites More sharing options...
Irap Posted January 25, 2010 Author Share Posted January 25, 2010 Okay, after hours of blood, sweat and tears, I managed to get the result I was hoping for. So I guess I'll share, eh? <? header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Content-Type: text/plain"); header("Content-Disposition: attachment; filename=\"info.ini\""); // send a file with the specified filename require_once('connect.inc.php'); // connect to database require_once('update.inc.php'); $sascm = new sascm(); $sascm->update($sascm_data); // update the file exit; ?> And in the "update.inc.php"... class sascm { public function update() { $information_query = mysql_query("SELECT * FROM `information` ORDER BY `id` ASC"); $file_data = ""; $sascm_header = "INFORMATION FILE\r \r "; while ($row=mysql_fetch_array($information_query)){ $sascm_data .= $row['info1'] . "\r "; } echo $sascm_data; return true; } } Of course, isn't exactly like mine. I removed some things modified it a little for other people to understand. However, it's probably not coded too well in professional PHP standards. And whenever I use \r, I have to insert a paragraph in the string afterwards too, otherwise there is no return and a weird symbol replaces the \r. Dunno what that's about. Also, the original idea was to add the echo $sascm_data; line to the first file, after the variable was returned. But that introduces a weird error about headers n stuff. I'm still teaching myself PHP. Any tips and suggestions are appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/189628-generating-files-for-visitors/#findComment-1001010 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.