Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file upload - register_globals is deactivated - plz help 1

Status
Not open for further replies.

Spidy6123

Technical User
Joined
May 30, 2002
Messages
227
Location
CA
Hey guys,

I'm using the following code to upload files to a server and it doesn't seem to be working correctly. You should know that register_globals is deactivated... I'm not sure, but I think that might be preventing this script from working... I was hoping there was something I can do with this to make it work..

Thanks guys, any advice is appreciated.

HTML
Code:
<form enctype="multipart/form-data" action="upload.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>


PHP
Code:
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = '/public_html/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
   echo "File is valid, and was successfully uploaded.\n";
} else {
   echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

?>


OUTPUT
Code:
Possible file upload attack!
Here is some more debugging info:Array
(
    [userfile] => Array
        (
            [name] => image.jpg
            [type] => 
            [tmp_name] => 
            [error] => 2
            [size] => 0
        )

)
 
c'mon..... little bit of self help needed here.

you downloaded the sample code from the php manual
(

you can see that the output has given you an error code (of 2) and in the page from which you have downloaded the code there is a link to what the errors mean
(
in this case you have attempted to upload a file that is larger in size than 30000 bytes (the MAX_FILE_SIZE hidden input box)
 
oh :(

thanks for you trouble...
 
no problem.

remember that the file upload limiter field is measured in bytes. so if you want to handle up to 10MB (say) you need to set the value to 10485760

remember also to ensure that the value in php.ini for uploaded file size and max post data are adequate for your needs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top