mousmoulis Posted September 27, 2006 Share Posted September 27, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/22237-problem-uploading-files/ Share on other sites More sharing options...
ober Posted September 27, 2006 Share Posted September 27, 2006 Where are you getting the files from? Quote Link to comment https://forums.phpfreaks.com/topic/22237-problem-uploading-files/#findComment-99566 Share on other sites More sharing options...
steveclondon Posted September 27, 2006 Share Posted September 27, 2006 see my code in this link to see if that helps. http://www.phpfreaks.com/forums/index.php/topic,109671.0.html Quote Link to comment https://forums.phpfreaks.com/topic/22237-problem-uploading-files/#findComment-99572 Share on other sites More sharing options...
mousmoulis Posted September 28, 2006 Author Share Posted September 28, 2006 My files are stored locally and using my browser i want to upload images to the webserver.the code is as followsbut I don't think it has to do with the codeThe echos are in Greek and are only messages appearing to the user to know if he has completed his task successfully or not.[table][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(); } }[/table] Quote Link to comment https://forums.phpfreaks.com/topic/22237-problem-uploading-files/#findComment-100086 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.