piznac Posted June 25, 2007 Share Posted June 25, 2007 Ok I had this working earlier,.. but wanted to update as well. And now things seem to have gotten screwed up. Any help would be appreciated.:: <?php $base = "/var/www/html/ups/"; $filename = $_FILES['file']['name']; echo $filename; if (@is_uploaded_file($_FILES["file"]["tmp_name"])) { copy($_FILES["file"]["tmp_name"], "$base" . "$filename"); } if (isset($filename)) { $filenameb= "$base" . "$filename"; echo $filenameb; $handle = fopen($filenameb, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $import="INSERT INTO orders(`or_date`,`ship_date`,`ship_via`,`job_name`,`job_desc`,`finishing`,`or_num`,`po_num`,`cust_name`,`tracking`,`pro_date`) values('$data[0]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[1]','$data[2]','$data[3]','','')ON DUPLICATE KEY UPDATE ship_date = VALUES(ship_date),ship_via = VALUES(ship_via),job_name = VALUES(job_name),job_desc = VALUES(job_desc),finishing = VALUES(finishing),po_num = (po_num),cust_name = VALUES(cust_name);"; mysql_query($import) or die("insert" . mysql_error()); fclose($handle); print "Import done"; } }else{ echo "No way hose"; } ?> This is the error Im getting: Warning: fgetcsv(): 6 is not a valid stream resource in /var/www/html/control/up.php on line 84 Now the file is there and is a csv, seperated by a comma. I dont get it. Quote Link to comment Share on other sites More sharing options...
piznac Posted June 25, 2007 Author Share Posted June 25, 2007 bump Quote Link to comment Share on other sites More sharing options...
piznac Posted June 25, 2007 Author Share Posted June 25, 2007 Can someone tell me what the 6 means here: "Warning: fgetcsv(): 6 " cause now Im getting 7 Quote Link to comment Share on other sites More sharing options...
Barand Posted June 25, 2007 Share Posted June 25, 2007 Could it be a permissions problem? Check read access permissions on base dir. Quote Link to comment Share on other sites More sharing options...
piznac Posted June 25, 2007 Author Share Posted June 25, 2007 It looks good with the dir "/var/www/html/ups/" 755 & the dir the script is in being 777. Quite stumped on this one Oh wait I think you were saying the root?... let me have a look at that. Quote Link to comment Share on other sites More sharing options...
Barand Posted June 25, 2007 Share Posted June 25, 2007 Instead of this (it will always be set as you set it a few lines above) if (isset($filename)) { try $filenameb= $base . $filename; if (file_exists($filenameb)) { Quote Link to comment Share on other sites More sharing options...
piznac Posted June 25, 2007 Author Share Posted June 25, 2007 Ok permissions look good. And I tried that but Im getting the same error. I might have changed something else in the process,.. here is what I have <?php require_once('sew.php'); require_once('sew.php'); $base = "/var/www/html/ups/"; $filename = $_FILES['file']['name']; if (@is_uploaded_file($_FILES["file"]["tmp_name"])) { copy($_FILES["file"]["tmp_name"], "$base" . "$filename"); } $filenameb= $base . $filename; if (file_exists($filenameb)) { echo "$filenameb</br>"; $handle = fopen("$filenameb", "r") or die("no go"); while (($data = fgetcsv($handle, 50000, "," )) !== FALSE ){ $import="INSERT INTO orders(`or_date`,`ship_date`,`ship_via`,`job_name`,`job_desc`,`finishing`,`or_num`,`po_num`,`cust_name`,`tracking`,`pro_date`) values('$data[0]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[1]','$data[2]','$data[3]','','')ON DUPLICATE KEY UPDATE ship_date = VALUES(ship_date),ship_via = VALUES(ship_via),job_name = VALUES(job_name),job_desc = VALUES(job_desc),finishing = VALUES(finishing),po_num = (po_num),cust_name = VALUES(cust_name);"; mysql_query($import) or die("insert" . mysql_error()); fclose($handle); print "Import done"; } }else{ echo "No way hose"; } ?> Wait,.. one sec ,.. yep still the same thing Quote Link to comment Share on other sites More sharing options...
piznac Posted June 25, 2007 Author Share Posted June 25, 2007 the file is there,.. or the fopen would have died on me I assume. Funny thing is earlier today I had this working. But then I got to messing with the sql connections and all (all removed) and it hasent functioned since. BTW do you know what the 7 in the error represents? Quote Link to comment Share on other sites More sharing options...
piznac Posted June 25, 2007 Author Share Posted June 25, 2007 ok when I take this out: while (($data = fgetcsv($handle, 50000, "," )) !== FALSE ){ $import="INSERT INTO orders(`or_date`,`ship_date`,`ship_via`,`job_name`,`job_desc`,`finishing`,`or_num`,`po_num`,`cust_name`,`tracking`,`pro_date`) values('$data[0]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[1]','$data[2]','$data[3]','','')ON DUPLICATE KEY UPDATE ship_date = VALUES(ship_date),ship_via = VALUES(ship_via),job_name = VALUES(job_name),job_desc = VALUES(job_desc),finishing = VALUES(finishing),po_num = (po_num),cust_name = VALUES(cust_name);"; mysql_query($import) or die("insert" . mysql_error()); fclose($handle); echo "Import Done"; } and leave just this: <?php $base = "/var/www/html/ups/"; $filename = $_FILES['file']['name']; if (@is_uploaded_file($_FILES["file"]["tmp_name"])) { copy($_FILES["file"]["tmp_name"], "$base" . "$filename"); } $filenameb= $base . $filename; if (file_exists($filenameb)){ echo "$filenameb</br>"; $handle = fopen("$filenameb", "r") or die("no go"); $data = fgetcsv($handle, 50000, "," ); }else{ echo "No way hose"; } ?> I dont get the error,. this is just strange. Or to narrow it down even further,. I dont get the error when I take this out: ON DUPLICATE KEY UPDATE ship_date = VALUES(ship_date),ship_via = VALUES(ship_via),job_name = VALUES(job_name),job_desc = VALUES(job_desc),finishing = VALUES(finishing),po_num = (po_num),cust_name = VALUES(cust_name)"; Is there an easier way to do this? Quote Link to comment Share on other sites More sharing options...
piznac Posted June 25, 2007 Author Share Posted June 25, 2007 Ok,.. mark this one as solved. Turns out this was a mysql error and not the fgetcsv as the error message eluded to. This is the final code,.. please if any one see any problems with this let me know. And thanks for the help Barrand,.. I still owe you that beer..lol: <?php $base = "/var/www/html/ups/"; $filename = $_FILES['file']['name']; if (@is_uploaded_file($_FILES["file"]["tmp_name"])) { copy($_FILES["file"]["tmp_name"], "$base" . "$filename"); } $filenameb= $base . $filename; if (file_exists($filenameb)){ echo "$filenameb</br>"; $handle = fopen("$filenameb", "r") or die("no file"); while (($data = fgetcsv($handle, 50000, "," )) !== FALSE ){ $import="INSERT INTO orders(`or_date`,`ship_date`,`ship_via`,`job_name`,`job_desc`,`finishing`,`or_num`,`po_num`,`cust_name`,`tracking`,`pro_date`) values('$data[0]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[1]','$data[2]','$data[3]','','') ON DUPLICATE KEY UPDATE ship_date = values(ship_date), ship_via = values(ship_via), job_name = values(job_name), job_desc = values(job_desc), finishing = values(finishing), po_num = values(po_num), cust_name = values(cust_name), tracking = values(tracking), pro_date = values(pro_date)"; mysql_query($import) or die("insert" . mysql_error()); } fclose($handle); echo "Import Done"; }else{ echo "Import Unsuccessful"; } ?> Quote Link to comment 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.