Jump to content

Upload script not working online but A ok on server?


esandra

Recommended Posts


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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.