esandra Posted September 14, 2010 Share Posted September 14, 2010 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,$databaseus… tabasepassword) or die(mysql_error()); @mysql_select_db($databasename) or die(mysql_error()); $lines = 0; $queries = ""; $linearray = array(); foreach(explode($lineseparator,$csvcon… 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. Quote Link to comment https://forums.phpfreaks.com/topic/213350-upload-script-not-working-online-but-a-ok-on-server/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 14, 2010 Share Posted September 14, 2010 You already have a recent thread for this. Don't start another one for the same problem. Surprisingly, creating more threads for the same problem actually reduces the chances of your question getting answered. Quote Link to comment https://forums.phpfreaks.com/topic/213350-upload-script-not-working-online-but-a-ok-on-server/#findComment-1110831 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.