File Upload

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
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

File Upload

Post by tecktalkcm0391 »

I am using this code:

Code: Select all

<?php

$uploaddir = 'images/';
$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>";

?>
And getting this:
File is valid, and was successfully uploaded.
Here is some more debugging info:Array
(
[userfile] => Array
(
[name] => untitled.JPG
[type] => image/pjpeg
[tmp_name] => /var/tmp/phpoy40P1
[error] => 0
[size] => 4354
)

)
And I can't figure out why!
Can anyone help... I've been trying for ever.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

:?:
Forgive me beeing dumb but is there a problem?
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Yeah, sorry I didn't really state the problem but the file doesn't upload at all.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Your code results would suggest otherwise.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Try modifying as follows:

Code: Select all

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
   echo "File is valid, and was successfully uploaded.\n";
   echo 'The File that was uploaded was placed here -----> '.$uploadfile."\n\n\n";
} else {
   echo "Possible file upload attack!\n";
}
Check (either via browser or via ftp, or if local via windows explorer) if the file exists in the location that gets reported... it'll be there, as your if statement will make sure of it...
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Yeah I know but the file doesn't show up in the folder...
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

nickvd wrote:Try modifying as follows:

Code: Select all

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
   echo "File is valid, and was successfully uploaded.\n";
   echo 'The File that was uploaded was placed here -----> '.$uploadfile."\n\n\n";
} else {
   echo "Possible file upload attack!\n";
}
Check (either via browser or via ftp, or if local via windows explorer) if the file exists in the location that gets reported... it'll be there, as your if statement will make sure of it...
Thanks, I got it. I feel stupid now.... :oops:
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Are you going to let us know how you solved the problem?
Post Reply