orangge Posted May 3, 2010 Share Posted May 3, 2010 Dear All, I have encountered some problems when i was doing some testing for the file upload. I found tat if the size of the graphic file is exactly 40kb, it won't be able to be uploaded even though i have set the size of the file to be uploaded not more than or equal to 40kb. Another problems i have encountered when i was tried to upload some .bmp files, some .bmp files were able to be uploaded and some weren't. It's not suppose to be happened because i have set the condition only allowed .jpeg, .gif and png files to be uploaded. I hope someone can help me. Thanks. Below are the codes: <?php if ((($_FILES["image"]["type"] == "image/gif") || ($_FILES["image"]["type"] == "image/jpeg") || ($_FILES["image"]["type"] == "image/pjpeg") || ($_FILES["image"]["type"] == "image/png")) && ($_FILES["image"]["size"] <= 40000)){ if ($_FILES["image"]["error"] > 0) { echo "Return Code: " . $_FILES["image"]["error"] . "<br />"; } else { echo "Upload has been successful."; if (file_exists("upload/" . $_FILES["image"]["name"])) { echo $_FILES["image"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["image"]["tmp_name"], "upload/" . $_FILES["image"]["name"]); } } } else { echo "Error."; } ?> Link to comment https://forums.phpfreaks.com/topic/200512-file-upload-help/ Share on other sites More sharing options...
anups Posted May 3, 2010 Share Posted May 3, 2010 40kb = 40*1024 = 40960 for file size use following code ($_FILES["image"]["size"] <= 40960)) for image type use following try function exif_imagetype http://in.php.net/manual/en/function.exif-imagetype.php Link to comment https://forums.phpfreaks.com/topic/200512-file-upload-help/#findComment-1052212 Share on other sites More sharing options...
orangge Posted May 3, 2010 Author Share Posted May 3, 2010 40kb = 40*1024 = 40960 for file size use following code ($_FILES["image"]["size"] <= 40960)) for image type use following try function exif_imagetype http://in.php.net/manual/en/function.exif-imagetype.php I have modified the code and tested with two bmp files. But one bmp file is working and the other is not working. Below is the code: <?php if ((($_FILES["image"]["type"] == "image/gif") || ($_FILES["image"]["type"] == "image/jpeg") || ($_FILES["image"]["type"] == "image/pjpeg") || ($_FILES["image"]["type"] == "image/png") || (exif_imagetype($_FILES["image"]["name"]) != IMAGETYPE_BMP)) && ($_FILES["image"]["size"] < 40960)){ if ($_FILES["image"]["error"] > 0) { echo "Return Code: " . $_FILES["image"]["error"] . "<br />"; } else { echo "Upload has been successful."; if (file_exists("upload/" . $_FILES["image"]["name"])) { echo $_FILES["image"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["image"]["tmp_name"], "upload/" . $_FILES["image"]["name"]); } } } else { echo "Error."; } ?> Link to comment https://forums.phpfreaks.com/topic/200512-file-upload-help/#findComment-1052232 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.