Lodius2000 Posted July 21, 2008 Share Posted July 21, 2008 my script is designed to display errors and redisplay the form if any are triggered, instead of processing the form, I use this architecture all the time and it is sound, so given the following code if ($_FILES['uploadfile']['type'] != 'image/jpeg'){ $errors[] = 'Please upload an image with an extension of .jpg or .jpeg'; } when i upload a tiff it should detect a non jpg file and display the error and redisplay the form, instead it tries to process the form and resize and all the other crap i have it do with the uploaded file, and since it is a tiff, imagecreatefromjpg() doesnt really work all that well is there something wrong with the conditions of my if() , i have echoed out $_FILES['uploadfile']['type'] and it tells me the right type Link to comment https://forums.phpfreaks.com/topic/115754-detecting-uploaded-file-type-and-error-checking/ Share on other sites More sharing options...
cooldude832 Posted July 21, 2008 Share Posted July 21, 2008 try my function I posted http://www.phpfreaks.com/forums/index.php/topic,207782.0.html Link to comment https://forums.phpfreaks.com/topic/115754-detecting-uploaded-file-type-and-error-checking/#findComment-595087 Share on other sites More sharing options...
Lodius2000 Posted July 21, 2008 Author Share Posted July 21, 2008 cooldude so i just need to adjust the $data integer to whichever type i want so for jpg i would put $data[1] in the function also could i define the function earlier and then make another if() that says if (! is_img){ //print error } Link to comment https://forums.phpfreaks.com/topic/115754-detecting-uploaded-file-type-and-error-checking/#findComment-595096 Share on other sites More sharing options...
cooldude832 Posted July 21, 2008 Share Posted July 21, 2008 example use <?php is_img($img_path){ $image_types = array("image/jpeg", "image/jpg", "image/pjpg", "image/pjpeg", "image/gif", "image/pgif", "image/png", "image/ppng"); $data = getimagesize($img_path); if(in_array($data[3],$image_types)){ return TRUE; } else{ return FALSE; } } #assume the function is in this file (the is_img function I wrote) $img = new Img_Class if(is_img($img->path)){ #its good do what you want } else{ #use your custom class error reporting $img->error_report("Its a broken image"); } ?> make sense Link to comment https://forums.phpfreaks.com/topic/115754-detecting-uploaded-file-type-and-error-checking/#findComment-595099 Share on other sites More sharing options...
Lodius2000 Posted July 21, 2008 Author Share Posted July 21, 2008 kinda but i dont know oop but to fit into my architecture i am pretty sure this line if(is_img($img->path)){ must return false, because if it were true it wont throw an error, i have no need of an else clause because all my errors tests if something is false, at that point they throw an error and redisplay the form so can I use if(! is_img($img->path)){ or should i change the functions if() to read if(! in_array($data[3],$image_types)){ also for $img_path, do I use $_FILES['uploadfile']['name'] or am i really not understanding this Link to comment https://forums.phpfreaks.com/topic/115754-detecting-uploaded-file-type-and-error-checking/#findComment-595103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.