uploading pdf file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Miha
Forum Newbie
Posts: 10
Joined: Mon Aug 21, 2006 12:44 pm

uploading pdf file

Post by Miha »

Hi,

guess what guys...i have a problem! :)
I'm trying to make a script for users, to upload files on my server. The problem is, i can only upload certain files. I would need to make this thing work for uploading .pdf files.

here is "my" script....

Code: Select all

$uploaddir = './slic/';
$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>";
i can upload some .txt, .zip files with this, but can not upload .pdf file.
here is what i get in my browser.

Code: Select all

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

)
type and tmp_name fields are empty...any idea how to make this thing work?


regards, Miha.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The "error" element is set to "2" which is:

Code: Select all

[feyd@home]>php -r "var_export(get_defined_constants());" | grep -Ein "upload.*?\b2\b"
44:  'UPLOAD_ERR_FORM_SIZE' => 2,
The form you are using specified a maximum size for the file. Your file was over that limit.
Miha
Forum Newbie
Posts: 10
Joined: Mon Aug 21, 2006 12:44 pm

Post by Miha »

feyd: yes, that was the problem.....thanks alot, you saved my day!!
Post Reply