a6april Posted January 30, 2013 Share Posted January 30, 2013 Hello. I am uploading a csv file and populating a data base. I have tried all kinds of things to get the header removed from the input but it either stops writing all together or breaks. Can anyone help me or does anyone have any suggestions? It works pretty good as intended now except for the one header record that gets added. Here is my script: <?php include '_inc/include.php'; if ($_FILES[csv][size] > 0) { //get the csv file $file = $_FILES[csv][tmp_name]; $handle = fopen($file,"r"); //loop through the csv file and insert into database do { if ($data[0]) { $mysql_query = mysql_query("INSERT INTO carbon_PA (closeddate, soldprice, streetnumber, streetname, streetsuffix, city, state, zip, gla, built, acres, taxid, photo, dom) VALUES ( '".addslashes($data[0])."', '".addslashes($data[1])."', '".addslashes($data[2])."', '".addslashes($data[3])."', '".addslashes($data[4])."', '".addslashes($data[5])."', '".addslashes($data[6])."', '".addslashes($data[7])."', '".addslashes($data[8])."', '".addslashes($data[9])."', '".addslashes($data[10])."', '".addslashes($data[11])."', '".addslashes($data[12])."', '".addslashes($data[13])."' ) "); } } while ($data = fgetcsv($handle,10000,",","'")); // //redirect } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Import a CSV File with PHP & MySQL</title> </head> <body> <?php if (!empty($_GET[success])) { echo "<b>Your file has been imported by import 55.</b><br><br>"; } //generic success notice ?> <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> Choose your file: <br /> <input name="csv" type="file" id="csv" /> <input type="submit" name="Submit" value="Submit" /> </form> <P> Display Data Contents <a href ='Data-Display.php'>here</a></P> </body> </html> Link to comment https://forums.phpfreaks.com/topic/273813-remove-the-header-data-from-a-file-upload/ Share on other sites More sharing options...
requinix Posted January 30, 2013 Share Posted January 30, 2013 Right after $handle = fopen($file,"r"); insert fgets($handle); That will read a line from the file and do absolutely nothing with it. Link to comment https://forums.phpfreaks.com/topic/273813-remove-the-header-data-from-a-file-upload/#findComment-1409088 Share on other sites More sharing options...
a6april Posted January 30, 2013 Author Share Posted January 30, 2013 WOW, That worked like a charm! Thank you Sooo Much!!! Link to comment https://forums.phpfreaks.com/topic/273813-remove-the-header-data-from-a-file-upload/#findComment-1409090 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.