alsouno Posted May 29, 2007 Share Posted May 29, 2007 hi, i'm working on a website where users can upload csv files and have it converted directly to a specific table in the sql db... it was working fine at first, but now it seems to give me the following error: Warning: file(./test.csv): failed to open stream: No such file or directory in ... once the file (in this case test.csv) is selected to upload, the form sends it to a page called upload.php i'm relatively new to php as im more experienced with jsp so my coding may not be the most efficient or the prettiest ... but anyways, here is some relevant code from upload.php: //upload file $target = "docs/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; $filename = "./".basename( $_FILES['uploaded']['name']) ; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } //add values to table $fcontents = file ($filename); for($i=0; $i<sizeof($fcontents); $i++) { $line = trim($fcontents[$i]); $arr = explode(",", $line); $sql = "insert into portfolio values ('". implode("','", $arr) ."')"; mysql_query($sql); echo $sql ."<br>"; if(mysql_error()) { echo mysql_error(); } } any help would be appreciated! Cheers Quote Link to comment https://forums.phpfreaks.com/topic/53457-failed-to-open-stream-no-such-file-or-directory/ Share on other sites More sharing options...
MadTechie Posted May 29, 2007 Share Posted May 29, 2007 try $fcontents = file ($target); Quote Link to comment https://forums.phpfreaks.com/topic/53457-failed-to-open-stream-no-such-file-or-directory/#findComment-264200 Share on other sites More sharing options...
alsouno Posted May 29, 2007 Author Share Posted May 29, 2007 try $fcontents = file ($target); wow that worked! thanks. could you explain the logic behind that, if its not too much trouble, so that i can avoid making the same mistake in the future? thanks againnnn Quote Link to comment https://forums.phpfreaks.com/topic/53457-failed-to-open-stream-no-such-file-or-directory/#findComment-264211 Share on other sites More sharing options...
MadTechie Posted May 29, 2007 Share Posted May 29, 2007 Sure thing.. $target = "docs/"; $target = $target . basename( $_FILES['uploaded']['name']) ; //<--setsup the target (being copied to) $ok=1; $filename = "./".basename( $_FILES['uploaded']['name']) ; // <--doesn get used if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) //<--moves from temp to target thus the file exists in $target Quote Link to comment https://forums.phpfreaks.com/topic/53457-failed-to-open-stream-no-such-file-or-directory/#findComment-264301 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.