problem in my uploading file script

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
hanhao
Forum Newbie
Posts: 14
Joined: Mon May 22, 2006 10:58 am

problem in my uploading file script

Post by hanhao »

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


problem for my uploading file script


hi i got a problem with my uploading script
here is the code on the page which shows the upload button.

[syntax="html"]
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="90000000" />
Choose a file to upload: <input name="uploadfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form> 
here is the code taken from php.net, it's in upload.php[/syntax]

Code: Select all

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

$uploaddir = "/website_root/color_scripts/querypic.jpg";
$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>";

?>
upon uploading i get the following error

Code: Select all

Possible file upload attack!
Here is some more debugging info:Array
(
    [uploadfile] => Array
        (
            [name] => querypic.jpg
            [type] => image/pjpeg
            [tmp_name] => d:\Program Files\xampp\tmp\phpBB.tmp
            [error] => 0
            [size] => 30489
        )

)
can anyone please help?


Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

First of all, put php tags in your php code...
Secondly, the $uploaddir is the dir in your system, i.e: c:\server_root\
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

Replace

Code: Select all

$uploaddir = "/website_root/color_scripts/querypic.jpg";
with:

Code: Select all

$uploaddir = "/website_root/color_scripts";
The reason is that you're trying to upload files to a file.
hanhao
Forum Newbie
Posts: 14
Joined: Mon May 22, 2006 10:58 am

Post by hanhao »

ok wrote:First of all, put php tags in your php code...
Secondly, the $uploaddir is the dir in your system, i.e: c:\server_root\
php tags are there
i set $uploaddir as the absolute path but it doesnt work
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

OK...
The upload dir should be: $uploaddir = "/website_root/color_scripts/" and not $uploaddir = "/website_root/color_scripts/querypic.jpg"; (as NiGHTFiRE posted).

PHP tags:
hanhao
Forum Newbie
Posts: 14
Joined: Mon May 22, 2006 10:58 am

Post by hanhao »

ok wrote:OK...
The upload dir should be: $uploaddir = "/website_root/color_scripts/" and not $uploaddir = "/website_root/color_scripts/querypic.jpg"; (as NiGHTFiRE posted).

PHP tags:
thnx for the help
unforturnately it doesnt work
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

lol.... I didn't notice that until now... :D

The name of the index in the $_FILES array have to be the same as the file input in your HTML....
In your case it will be: $_FILES['uploadfile'] instead of $_FILES['userfile'].
Post Reply