Jump to content

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

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.