giraffemedia Posted September 30, 2011 Share Posted September 30, 2011 Hello, I want to put together a little script that does the following but I'm not sure how to approach it… 1 - user chooses a csv file up to 5mb in size filled with competition entries. There is one competition entry per line. 2 - The contents of this csv then load into a html textarea on the page 3 - The user clicks a 'pick winner' button and the script chooses a random line from the textarea and assigns it to the variable $winner which prints to the browser 4 - If the user wishes they can click on the button to select more winners if necessary. I'm a bit stumped about the best way to do this. I don't really want to get into uploading the csv file to a directory permanently. Can anyone point me in the right direction for doing this please? Thanks, James Quote Link to comment https://forums.phpfreaks.com/topic/248174-put-csv-file-contents-into-text-area-and-choose-random-line/ Share on other sites More sharing options...
premiso Posted September 30, 2011 Share Posted September 30, 2011 The only time the file is stored permanently is if you actively move the file in the php script. You can read from the file using the temporary file location. The location can be found with something like: $tmp_name = $_FILES["formfield"]["tmp_name"]; $fh = fopen($tmp_name, 'r'); if ($fh !== FALSE) { while (($data = fgetcsv($fh, 1000, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } } fclose($fh); } Something like that should do what you are looking for. Quote Link to comment https://forums.phpfreaks.com/topic/248174-put-csv-file-contents-into-text-area-and-choose-random-line/#findComment-1274421 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.