rahul19dj Posted August 3, 2012 Share Posted August 3, 2012 I cant get to understand what am I doing wrong here. It keeps saying not a csv file . But I haved saved the file as csv file if($_FILES["file"]["type"] != "application/vnd.ms-excel"){ die("This is not a CSV file."); } elseif(is_uploaded_file($_FILES['file']['tmp_name'])){ //Connect to the database $dbhost = 'localhost'; $dbuser = 'xxxxxxxx'; $dbpass = 'xxxxxxxx'; $dbname = 'xxxxxxxx'; $link = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql server'); mysql_select_db($dbname); //Process the CSV file $handle = fopen($_FILES['file']['tmp_name'], "r"); $data = fgetcsv($handle, 1000, ";"); //Remove if CSV file does not have column headings while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $att0 = mysql_real_escape_string($data[0]); $att1 = mysql_real_escape_string($data[1]); $att2 = mysql_real_escape_string($data[2]); $att3 = mysql_real_escape_string($data[3]); $att0 = mysql_real_escape_string($data[4]); $att1 = mysql_real_escape_string($data[5]); $att2 = mysql_real_escape_string($data[6]); $att3 = mysql_real_escape_string($data[7]); $att3 = mysql_real_escape_string($data[8]); $sql = "INSERT INTO `tempusers` ( `fname` , `mobile` , `center` , `balcf` , `used` , `newbal` , `summary` , `date` , `smssend` ) VALUES ('" . $att0 . "', '" . $att1 . "', '" . $att2 . "', '" . $att3 . "', '" . $att4 . "', '" . $att5 . "', '" . $att6 . "', '" . $att7 . "', '" . $att8 . "')"; mysql_query($sql); } mysql_close($link); echo "CSV file successfully imported."; } else{ die("You shouldn't be here"); } Link to comment https://forums.phpfreaks.com/topic/266623-help-in-uploading-csv-through-php-in-mysql/ Share on other sites More sharing options...
Mahngiel Posted August 3, 2012 Share Posted August 3, 2012 what is the value of var_dump($_FILES); ? According to filext.com, a csv can have types of: text/comma-separated-values, text/csv, application/csv, application/excel, application/vnd.ms-excel, application/vnd.msexcel, text/anytext you can create an array of those types, and check if the $_FILES['type'] is in_array of it. Link to comment https://forums.phpfreaks.com/topic/266623-help-in-uploading-csv-through-php-in-mysql/#findComment-1366512 Share on other sites More sharing options...
rahul19dj Posted August 3, 2012 Author Share Posted August 3, 2012 How will I get this ? Link to comment https://forums.phpfreaks.com/topic/266623-help-in-uploading-csv-through-php-in-mysql/#findComment-1366513 Share on other sites More sharing options...
Mahngiel Posted August 3, 2012 Share Posted August 3, 2012 by executing var_dump($_FILES); when the post is first in scope. Link to comment https://forums.phpfreaks.com/topic/266623-help-in-uploading-csv-through-php-in-mysql/#findComment-1366514 Share on other sites More sharing options...
rahul19dj Posted August 3, 2012 Author Share Posted August 3, 2012 I dont have a php compiler I just modify in notepad++ Link to comment https://forums.phpfreaks.com/topic/266623-help-in-uploading-csv-through-php-in-mysql/#findComment-1366515 Share on other sites More sharing options...
Mahngiel Posted August 3, 2012 Share Posted August 3, 2012 Quote I dont have a php compiler I just modify in notepad++ how the hell are you running your code then?!?! Link to comment https://forums.phpfreaks.com/topic/266623-help-in-uploading-csv-through-php-in-mysql/#findComment-1366516 Share on other sites More sharing options...
rahul19dj Posted August 3, 2012 Author Share Posted August 3, 2012 I tried all the types no luck ..... HELP Link to comment https://forums.phpfreaks.com/topic/266623-help-in-uploading-csv-through-php-in-mysql/#findComment-1366517 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.