Jump to content


Photo

Problem Uploading Files


  • Please log in to reply
3 replies to this topic

#1 mousmoulis

mousmoulis
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 27 September 2006 - 12:19 PM

I have made a page through which I upload images to the webserver. Jpeg, gif, png are only accepted. 90% of them are uploaded successfully. But there is a problem with the other 10%. What is happening is that for some reason while in the 90% of the images my page can recognize the size and the type of the image in the other 10% it can't. When I echo the $_FILES['image']['type'], $_FILES['image']['size'] I get nothing and zero respectively. So when I check whether the file is jpeg, png or gif I get the message that the file is not in the right format. But even if I comment out the checking about the file size or type although it looks as if the file was uploaded the file isnot present in the server. It is as if the images aren't thought to be valid files although in my PC they are recognised as e.g. png file with size = 121kb. I have even tried to convert the images to different format or size but the result remains the same. Does anybody knows why some images are recognised and other are not?

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 27 September 2006 - 01:05 PM

Where are you getting the files from?

Info: PHP Manual


#3 steveclondon

steveclondon
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 27 September 2006 - 01:15 PM

see my code in this link to see if that helps.

http://www.phpfreaks...c,109671.0.html

#4 mousmoulis

mousmoulis
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 28 September 2006 - 07:14 AM

My files are stored locally and using my browser i want to upload images to the webserver.


the code is as follows
but I don't think it has to do with the code
The echos are in Greek and are only messages appearing to the user to know if he has completed his task successfully or not.

[tr][td]if ($_FILES['appScreenshot']['name'])

{

$uploaddir = "../images/screenshots/";

$allowed = array('image/gif','image/jpeg','image/png');

$verified_ext = false;



$extension = pathinfo($_FILES['appScreenshot']['name']);

$extension = $extension['extension'];







echo $_FILES['appScreenshot']['size'];


if(in_array($_FILES['appScreenshot']['type'], $allowed))

{

$verified_ext = true;

}

else

{

echo "Η επέκταση του αρχείου της εικόνας δεν είναι έγκυρη. Πρέπει να είναι jpg, gif, png, jpeg";

exit();

}



if($appScreenshot!="")

{

if(is_dir($uploaddir))

{

if(!unlink($uploaddir.$appScreenshot))

{

echo "Δεν είναι δυνατή η διαγραφή της υφιστάμενης εικόνας. Ξαναπροσπαθήστε.";

exit();

}

}

else

{

echo "Η εικόνα δεν είναι καταχωρισμένη σε έγκυρη διαδρομή στο server";

exit();

}

}





$screenshot = $appID.".".$extension;

$final_upload_file = $uploaddir.$screenshot;





if($verified_ext == true)

{

if($_FILES['appScreenshot']['size'] > $max_size)

{

echo "Το μέγεθος της εικόνας είναι πολύ μεγάλο. Εισάγετε εικόνα με μικρότερο μέγεθος.";

exit();

}



if($_FILES['appScreenshot']['size'] == 0)

{

echo "Η εικόνα έχει μηδενικό μέγεθος. Εισάγετε εικόνα με μεγαλύτερο μέγεθος.";

exit();

}



if(is_uploaded_file($_FILES['appScreenshot']['tmp_name']))

{

if(is_dir($uploaddir))

{

if(!file_exists($final_upload_file))

{

if(!move_uploaded_file($_FILES['appScreenshot']['tmp_name'],$final_upload_file))

{

echo "Δεν ήταν δυνατή η αποστολή του αρχείου εικόνας στο sever";

exit();

}



}

else

{

echo "Υπάρχει ήδη αρχείο καταχωρισμένο για την τρέχουσα εφαρμογή";

exit();

}

}

else

{

echo "Η διαδρομή αποθήκευσης της εικόνας δεν είναι έγκυρη";

exit();

}

}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users