Jump to content

failed to open stream: no such file or directory


alsouno

Recommended Posts

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  ;D ... 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

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 :)

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.