kenwvs Posted July 5, 2006 Share Posted July 5, 2006 I have this basic script (below) that is getting the information from a form, and then converting it into a csv file.Is it possible to have the fopen statement get the filename from the form that it is getting all the data from, and then save the same data to this form in a csv format?I went with the process of listing each item individually (instead of using an array) as I needed one item to be in a different order in the csv file than it is listed on the form, and although I beleive there is a way to organize it, this is my first attempt at PHP and I was getting confused.I need to let each person who fills out the form input what they want the filename to be called, and it needs to be saved in csv format.Thanks,Ken<?php$writetocsv = $_POST['item_title'] . "," . $_POST['item_category'] . "," . $_POST['item_type'] . "," . $_POST['quantity_available'] . "," . $_POST['starting_bid'] . "," . $_POST['bid_increment'] . "," . $_POST['reserve_price'] . "," . $_POST['duration'] . "," . $_POST['auto_relist'] . "," . $_POST['city'] . "," . $_POST['state'] . "," . $_POST['country'] . "," . $_POST['item_description'] . "," . $_POST['paypal_id'] . "," . $_POST['hit_counter'] . "," . $_POST['end_hour'] . "\n";$file = fopen([color=red]filename_from_form[/color]]","a");fwrite ($file,$writetocsv);fclose ($file);?> Quote Link to comment https://forums.phpfreaks.com/topic/13788-fopen-can-i-get-a-filename-from-a-form-that-it-is-calling-data-from/ Share on other sites More sharing options...
dwees Posted July 5, 2006 Share Posted July 5, 2006 I'm doing that exact thing in a script I just wrote:Basically a user choose a name for a quiz they want to create, and my script creates a file with that name. [code]Get user to enter name of quiz in form<snip>// Ths collects the filename.$quiz_name = $_POST['quizname'];// This appends the proper ending, here it's xml, but you want cvs.$quiz_file_name = "$quiz_name".".xml";// Here it creates the string I'm going to put into the file.$stringAPP = "<?xml version=\"1.0\"?>\n"."<QUIZ>\n\n"."<TITLE>"."$quiz_name"."</TITLE>"; // Open the file to write$fh = fopen("$quiz_file_name", 'w') or die("can't create file");// Add the strings in XML formatfwrite($fh, "$stringAPP");fclose($fh);// I have to create a temporary file to store data between runs off the code (since it// recursively calls itself) so I'm confusing the name of the file up for a bit of security.$temp = md5("temporaryfile");// open the file and add the temporary data. remember to get rid of this file later.$fh = fopen($temp, 'w') or die("can't create file");fwrite($fh, "$quiz_file_name");fclose($fh);[/code]Does this help? Quote Link to comment https://forums.phpfreaks.com/topic/13788-fopen-can-i-get-a-filename-from-a-form-that-it-is-calling-data-from/#findComment-53616 Share on other sites More sharing options...
kenwvs Posted July 5, 2006 Author Share Posted July 5, 2006 I am thinking that is going to do exactly what I wanted it to do........awesome. Thank You.After they complete the quiz, what are you doing with the results?Do you have to manually get rid of the file later? After this file is created and stored, I am hoping to figure out a way to email it back to the original user, or have it come back on the screen where they can save it locally, and once it has been emailed or saved, it can be discarded.Thanks again,Ken Quote Link to comment https://forums.phpfreaks.com/topic/13788-fopen-can-i-get-a-filename-from-a-form-that-it-is-calling-data-from/#findComment-53632 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.