I have a code block that loads an image and creates a sketch if the extension is a lowercase jpg, but it will not load the image if it is an uppercase JPG. When I rename an image, for example. example.JPG to example.jpg, it will be downloaded. But example.JPG will not load, and I will not get an error. That makes no sense to me. Does anyone have an explanation for this? Here is my code:
<?php function createThumbnail($filename) { require 'config.php'; if(preg_match('/[.](jpg)$/', $filename)) { $im = imagecreatefromjpeg($filename.$path_to_image_directory); } else if (preg_match('/[.](gif)$/', $filename)) { $im = imagecreatefromgif($path_to_image_directory . $filename); } else if (preg_match('/[.](png)$/', $filename)) { $im = imagecreatefrompng($path_to_image_directory . $filename); } $ox = imagesx($im); $oy = imagesy($im); $nx = $final_width_of_image; $ny = $final_height_of_image; $nm = imagecreatetruecolor($nx, $ny); imagecopyresampled($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy); if(!file_exists($path_to_thumbs_directory)) { if(!mkdir($path_to_thumbs_directory)) { die("There was a problem. Please try again!"); } } imagejpeg($nm, $path_to_thumbs_directory . $filename); $tn = '<img src="' . $path_to_thumbs_directory . $filename . '" alt="image" />'; $tn .= '<br />Congratulations. Your file has been successfully uploaded, and a thumbnail has been created.'; echo $tn; } ?>
Configuration file:
<?php $final_width_of_image = 300; $final_height_of_image = 300; $path_to_image_directory = ''; $path_to_thumbs_directory = '-tn'; ?>
source share