Jump to content


Photo

Upload Script.... extremely irritating....


  • Please log in to reply
2 replies to this topic

#1 vidyashankara

vidyashankara
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 28 July 2006 - 07:59 PM

index.php

echo "<p><img src=/images/part2index.jpg>

<form enctype=multipart/form-data method=post action=upload.php>

<input type=file name=file />

  <input type=image src=/images/uploadindex.jpg value=Upload>

</form>";

upload.php

ini_set("display_errors",1);
$time=time();

// Where the file is going to be placed
chdir("uploaded_pdb");

mkdir($time,0777);
chdir($time);
$target_path = "uploaded_pdb/$time/";



/* Add the original filename to our target path. Result is "uploads/filename.extension" */

$filename = basename($_FILES['file']['name']);
$target_path = $target_path . $filename;




// This is how we will get the temporary file...

$tmpname = $_FILES['file']['tmp_name'];
$move = move_uploaded_file($tmpname, $target_path);


if ($move) {

    echo "The file $filename has been uploaded";

} else {

    echo "There was an error uploading the file, $filename, please try again!";

}
print "<pre>";
echo 'Here is some more debugging info:<br>';
print_r($_FILES);
print "</pre>";


Output of array file

Array
(
    [file] => Array
        (
            [name] => 1.txt
            [type] => text/plain
            [tmp_name] => /tmp/phpyxLK1B
            [error] => 0
            [size] => 666
        )

)

the error i get is

Warning: move_uploaded_file(uploaded_pdb/1154116683/1.txt): failed to open stream: No such file or directory in /var/www/html/pdbreader/upload.php on line 20

Warning: move_uploaded_file(): Unable to move '/tmp/phpyxLK1B' to 'uploaded_pdb/1154116683/1.txt' in /var/www/html/pdbreader/upload.php on line 20
There was an error uploading the file, 1.txt, please try again!



whats wrong??? the code looks perfect to me...

#2 lead2gold

lead2gold
  • Members
  • PipPipPip
  • Advanced Member
  • 164 posts
  • LocationOttawa, On

Posted 28 July 2006 - 08:07 PM

// Where the file is going to be placed
chdir("uploaded_pdb");

mkdir($time,0777);
chdir($time);
$target_path = "uploaded_pdb/$time/";

if you changed to the directory successfully then the new target_path is this:
$target_path = "$time/";


#3 vidyashankara

vidyashankara
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 28 July 2006 - 08:12 PM

i changed it to
$target_path = "";

because i changed to $time before itself. Works great now. Thanks :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users