Forum Moderators: coopster

Message Too Old, No Replies

File upload OK., but no file in the directory

         

rekhad

10:18 pm on Mar 9, 2006 (gmt 0)

10+ Year Member



I have uploaded a image file through a form.The file upload was successful,but image file (bullslogo.jpg)does not exist in the directory(C:/images).
The code is

<?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
)

)

Steerpike

3:36 am on Mar 10, 2006 (gmt 0)

10+ Year Member



C:/images needs a / on the end of it.

At the moment it's trying to write a file called:
C:/imagesbullslogo.jpg

omoutop

7:04 am on Mar 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You will also need read/write enabled in your folder. CHMOD can help you there

rekhad

3:05 pm on Mar 10, 2006 (gmt 0)

10+ Year Member



What I see is that IE gives me file type .pjpeg rather than .jpg

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
)

)