Forum Moderators: coopster
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
$uploaddir = 'C:/images';
if(isset($uploaddir))
print"I exist";
else
print"I do not exist";
if($_FILES['userfile']['name'] == '') {
echo 'You did not select a photo to upload';
}
elseif($_FILES['userfile']['size'] == 0) {
echo 'There appears to be a problem with the photo your are uploading';
}
elseif(!getimagesize($_FILES['userfile']['tmp_name'])) {
echo 'The photo you selected is not a valid image file';
}
else { $uploadfile = "$uploaddir.($_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>";
?>
the output is
I exist
File is valid, and was successfully uploaded.
Here is some more debugging info:Array
(
[userfile] => Array
(
[name] => bullslogo.jpg
[type] => image/pjpeg
[tmp_name] => C:/Program Files/EasyPHP1-8\tmp\php1D.tmp
[error] => 0
[size] => 4430
)
)
Please see the output one more time.Also my if statement says that file is not a jpg file.
In my "images" directory I get a php file named
.basename(Array{['userfile']}{['name']}) not an image file
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
$uploaddir = 'C:/images/';
if(isset($uploaddir))
print"I exist<br>";
else
print"I do not exist";
if($_FILES['userfile']['type']=="image/jpg"¦¦$_FILES['userfile']['name']=="image/pjpeg"){
echo' i am an image';
}
else{
echo'not a ".jpg"image ';
}
if($_FILES['userfile']['name'] == '') {
echo 'You did not select a photo to upload';
}
elseif($_FILES['userfile']['size'] == 0) {
echo 'There appears to be a problem with the photo your are uploading';
}
elseif(!getimagesize($_FILES['userfile']['tmp_name'])) {
echo 'The photo you selected is not a valid image file';
}
else { $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>";
?>
my output is......
I exist
not a ".jpg"image
File is valid, and was successfully uploaded.
Here is some more debugging info:Array
(
[userfile] => Array
(
[name] => Henry.jpg
[type] => image/pjpeg
[tmp_name] => C:/Program Files/EasyPHP1-8\tmp\php5.tmp
[error] => 0
[size] => 9938
)
)