travelkind Posted November 23, 2009 Share Posted November 23, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/182563-functionfile-failed-to-open-stream-no-such-file-or-directory/ Share on other sites More sharing options...
premiso Posted November 23, 2009 Share Posted November 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/182563-functionfile-failed-to-open-stream-no-such-file-or-directory/#findComment-963646 Share on other sites More sharing options...
travelkind Posted November 23, 2009 Author Share Posted November 23, 2009 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/ Quote Link to comment https://forums.phpfreaks.com/topic/182563-functionfile-failed-to-open-stream-no-such-file-or-directory/#findComment-964019 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.