sangeetha Posted June 26, 2008 Share Posted June 26, 2008 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 More sharing options...
Synook Posted June 26, 2008 Share Posted June 26, 2008 What does your code look like?Did you use absolute URLs? Link to comment Share on other sites More sharing options...
sangeetha Posted June 26, 2008 Author Share Posted June 26, 2008 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 More sharing options...
Synook Posted June 26, 2008 Share Posted June 26, 2008 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 More sharing options...
sangeetha Posted June 26, 2008 Author Share Posted June 26, 2008 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 More sharing options...
Synook Posted June 26, 2008 Share Posted June 26, 2008 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 More sharing options...
sangeetha Posted June 27, 2008 Author Share Posted June 27, 2008 Cant we do similar like uploading photos or image on other web sites. we might have our image in our pc and we upload that to the corresponding website online. Link to comment Share on other sites More sharing options...
Synook Posted June 27, 2008 Share Posted June 27, 2008 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 More sharing options...
sangeetha Posted June 27, 2008 Author Share Posted June 27, 2008 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 More sharing options...
sangeetha Posted June 27, 2008 Author Share Posted June 27, 2008 Thanks a lot Synook. its working good now. the datas are getting uploaded to the database Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.