this is a .csv to .sql uploader..it works fine on my local server but when i upload it, it doesn't do anything
require_once("connection.php");
$ebits = ini_get('error_reporting');
error_reporting($ebits ^ E_NOTICE);
$file = $_POST['file'];
if($_POST['file']==""){
echo ("<meta http-equiv='Refresh' content='0;url=add.php'>");
}
$databasehost = "host";
$databasename = "temp";
$databasetable = "tbl";
$databaseusername ="name";
$databasepassword = "pass";
$fieldseparator = ",";
$lineseparator = "\n";
$csvfile = $_FILES['file']['name'];
if(!file_exists($csvfile)) {
/** when i execute this script, it goes directly to this part. It simply echoes the string below. **/
echo "File not found. Make sure you specified the correct path.\n";
exit;
}
$file = fopen($csvfile,"r");
if(!$file) {
echo "Error opening data file.\n";
exit;
}
$size = filesize(realpath($csvfile)); /****here is the part where it gets the address/path and the file name****/
if(!$size) {
echo "File is empty.\n";
exit;
}
$csvcontent = fread($file,$size);
fclose($file);
$con = @mysql_connect($databasehost,$databaseusername,$da tabasepassword) or die(mysql_error());
@mysql_select_db($databasename) or die(mysql_error());
$lines = 0;
$queries = "";
$linearray = array();
foreach(explode($lineseparator,$csvcontent) as $line) {
$lines++;
$line = trim($line," \t");
$line = str_replace("\r","",$line);
$line = str_replace("'","\'",$line);
$linearray = explode($fieldseparator,$line);
$linemysql = implode("','",$linearray);
if($addauto)
$query = "insert into $databasetable values('','$linemysql');";
else
$query = "insert into $databasetable values('$linemysql');";
$queries .= $query . "\n";
@mysql_query($query);
}
@mysql_close($con);
Also, my line breaker is "/n" but when i save as an xlsx file into csv, it doesn't automatically put "/n" after every line, in fact it doesn't put anything ecxept for the commas that separate the fields,,,so for my script to successfully upload my temp.csv, i had to type in "/n" in every line.... What can you suggest I do about this ??
Thank you very much for your time.