Jump to content

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...
Link to comment
https://forums.phpfreaks.com/topic/15925-upload-script-extremely-irritating/
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]
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.