Jump to content

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


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/

 

 

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.