Jump to content

[SOLVED] fgetcsv problem


piznac

Recommended Posts

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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";
   }

?>

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.