Current location: Hot Scripts Forums » Programming Languages » PHP » upload script not working online but A ok on server


upload script not working online but A ok on server

Reply
  #1 (permalink)  
Old 09-13-10, 08:18 PM
esandra esandra is offline
Newbie Coder
 
Join Date: Aug 2009
Posts: 47
Thanks: 1
Thanked 0 Times in 0 Posts
upload script not working online but A ok on server

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.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Status2k PRICE ON HOLD - Server Monitoring Script! status2k General Advertisements 0 12-08-08 08:19 AM
Script won't always run on server patter PHP 2 08-19-07 02:34 PM
Online grade reporting script for linux server anjum Script Requests 0 08-10-07 03:54 PM
CGI Script Problem on new Linux server sujata_ghosh Perl 2 11-13-06 11:41 PM
Script Installation, Server Administration flashweb Job Offers & Assistance 0 10-13-06 06:59 AM


All times are GMT -5. The time now is 08:42 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.