Jump to content

import csv


sangeetha

Recommended Posts

When uploading csv into the database, it is getting uploaded if i do in offline. but getting problem when i try to do the same in online. The error i get is " the specified path is not correct". can anyone help me to solve this problem. Thanks.

Link to comment
Share on other sites

What does your code look like?Did you use absolute URLs?

Link to comment
Share on other sites

What does your code look like?Did you use absolute URLs?
This is the code that i have. I dont know how to get the path of the file which i want to upload.
session_start();$fileloc=$_POST['filename'];$exam=@$_SESSION["exam"];//echo "exam".$exam;$file3 = $exam;echo $file3;$path = $fileloc;$file = basename($path);		 // $file is set to "index.php"$fieldseparator = "\t";$lineseparator = "\n";$csvfile = $fileloc;echo "csvfile".$csvfile;$addauto =1;if(!file_exists($csvfile)) {	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;}//echo $file;$size = filesize($csvfile);//echo $size;if(!$size) {	echo "File is empty.\n";	exit;}$csvcontent = fread($file,$size);fclose($file);mysql_connect($dbhost, $dbuser, $dbpass) or die("did'nt connect to mysql1");mysql_select_db($dbname) or die ("no database");$result = mysql_query("SELECT * FROM $exam order by count");$count=0;while($row = mysql_fetch_array($result))  {   $count= $row['count'];  }if($count==0)  $count=0;  else  $count=$count; // echo $count."<br>";  @mysql_close($con);mysql_connect($dbhost, $dbuser, $dbpass) or die("did'nt connect to mysql1");mysql_select_db($dbname) or die ("no database");$databasetable = "$file3";$lines = 0;$queries = "";$linearray = array();foreach(split($lineseparator,$csvcontent) as $line) {	$count = $count + 1;	$lines++;	$line = trim($line," \t");	$line = str_replace("\r","",$line);		    //$line = str_replace(",","\,",$line);	$line = str_replace("'","\'",$line);	$linearray=array();	$linearray = explode($fieldseparator,$line);		$linemysql = implode("','",$linearray);			if($addauto)		{//$query = "insert into $databasetable values('','$linemysql');";		$query = "insert into $databasetable VALUES('$count','$linemysql');";	//$result1 = mysql_query($query) or die("didn't query for  insert");		echo $query."<br>";		}	else		$query = "insert into $databasetable values('$linemysql');";			$queries .= $query . "\n";	@mysql_query($query);	//echo $query ."<br>\n";}echo " TSV File imported to the database";@mysql_close($con);

Link to comment
Share on other sites

Did you upload the file you want to place in the database along with the above page? So say you enter file.csv into the form, do you have file.csv in the same directory as that script?

Link to comment
Share on other sites

No.. i dint. using ftp we are loading the pages. but when uploading how can i choose from it. can you explain me.pls. i have the file that i want to upload in my desktop.how to upload that file when i am running the project online? similar like uploading image. we might have our image in our pc and we upload that to the corresponding website online. Thanks in advance.

Link to comment
Share on other sites

Well that script just opens a CSV file (already on your server's filesystem) and parses data from the file into a database table.You can use FTP to upload your CSV file. Say it was called file.csv, just upload file.csv into the same directory as the PHP script, and then cite "file.csv" in the form.

Link to comment
Share on other sites

Umm... I'm not sure I understand. Do you want to INSERT image data into a database table?

Link to comment
Share on other sites

Umm... I'm not sure I understand. Do you want to INSERT image data into a database table?
No. i just said an example. i want to upload the csv file into database. I have tried as what you said. And thanks it is getting moved to that folder. Now its not reading the content of that file which i have uploaded.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...