I getimagesize() uploaded by users with getimagesize() This is how:
$imageinfo = getimagesize($file['tmp_name']); if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg' && $imageinfo['mime'] != 'image/png') { $data['error'] = 'ΠΡΠΈΠ±ΠΊΠ° Π·Π°Π³ΡΡΠ·ΠΊΠΈ. ΠΠΎΠΏΡΡΡΠΈΠΌΡΠ΅ ΡΠΎΡΠΌΠ°ΡΡ: .jpeg .gif .png'; echo json_encode( $data ); exit; } else { list($width, $height) = getimagesize($file['tmp_name']); if ($width < $minWidth || $height < $minHeight || $height > $maxHeight || $width > $maxWidth){ $data['error'] = 'ΠΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΠ΅ Π½Π΅ ΠΌΠΎΠΆΠ΅Ρ Π±ΡΡΡ ΠΌΠ΅Π½ΡΡΠ΅ '.$minWidth.' ΠΈ Π±ΠΎΠ»ΡΡΠ΅ '.$maxWidth.' ΠΏΠΈΠΊΡΠ΅Π»Π΅ΠΉ <br> ΠΏΠΎ ΠΎΠ΄Π½ΠΎΠΉ ΠΈΠ· ΡΡΠΎΡΠΎΠ½. ΠΠΎΠΆΠ°Π»ΡΠΉΡΡΠ° Π²ΡΠ±Π΅ΡΠΈΡΠ΅ Π΄ΡΡΠ³ΠΎΠ΅ ΡΠΎΡΠΎ.'; echo json_encode( $data ); exit; } } That is a check for mime types. Everything works perfectly with different formats, but when users load a .txt file instead of images, the server issues 500 (Internal Server Error) with the words LOG.error: exception 'ErrorException' with message 'getimagesize(): Read error!
Tried to do so:
try {getimagesize($file['tmp_name']);} catch (Exception $e) { } if ($e === FALSE) { //ERROR } Did not help. How to do it so that in case of an error of execution of getimagesize () there was not a 500 error, but a response in the form echo json_encode( $error ); ?