Jump to content

Archived

This topic is now archived and is closed to further replies.

vidyashankara

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

Recommended Posts

index.php
[code]

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>";
[/code]

upload.php

[code]
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>";

[/code]

Output of array file
[code]

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

)
[/code]

the error i get is

[code]
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!

[/code]


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

Share this post


Link to post
Share on other sites
[code]
// Where the file is going to be placed
chdir("uploaded_pdb");

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

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

Share this post


Link to post
Share on other sites

×

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.