Jump to content

[function.file]: failed to open stream: No such file or directory


travelkind

Recommended Posts

Okay I wrote this little script to upload a csv file that is located on my webhosts server to a mysql database.  Something is wrong because I am getting the following error:

 

Warning: file(./html/beer/uploads/filename.csv) [function.file]: failed to open stream: No such file or directory in /home/content/d/l/a/dlanden/html/beer/uploads/upload_csv_mysql.php on line 12

insert into sunocoimport values ('')

Column count doesn't match value count at row 1

 

I did a syntax check and everything checked out.  Here is the code:

 

$fcontents = file ('./html/beer/uploads/filename.csv');

  # expects the csv file to be in the same dir as this script

 

  for($i=0; $i<sizeof($fcontents); $i++) {

      $line = trim($fcontents[$i]);

      $arr = explode("\,", $line);

      #if your data is comma separated

      # instead of tab separated,

      # change the '\t' above to ','

   

      $sql = "insert into sunocoimport values ('".

                  implode("','", $arr) ."')";

      mysql_query($sql);

      echo $sql ."<br>\n";

      if(mysql_error()) {

        echo mysql_error() ."<br>\n";

      }

}

?>

 

I am a newbie so any advice would be appreciated!

 

Well the error is obvious, it cannot find the file. So you need to figure out the right path:

 

$fcontents = file ('/html/beer/uploads/filename.csv'); 

 

Try that and see if it works. given that /html/beer etc is your webserver path. If it is not you need to fix that portion.

Okay I took the . out but still got the following error:

 

Warning: file(/html/beer/uploads/filename.csv) [function.file]: failed to open stream: No such file or directory in /home/content/d/l/a/dlanden/html/beer/uploads/upload_csv_mysql.php on line 12

insert into sunocoimport values ('')

Column count doesn't match value count at row 1

 

As far as locations, the filename.csv and this script are both in the same location:

/html/beer/uploads/

 

 

Archived

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

×
×
  • 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.