I have been trying to make the automatic image gallery work for some time now and i am unable to find what is wrong
I hope someone can help, here is my code:
<?php if (isset($_GET['img'])) { if(file_exists($_GET['img'])){ ignore_user_abort(true); set_time_limit(120); ini_set('memory_limit', '512M'); $src_size = getimagesize($_GET['img']); if($src_size ===false){ die("This is not an image"); } $thumb_width = 200; $thumb_heigth = 200; //print_r($src_size); if ($src_size['mime'] === 'image/jpeg') { $src=imagecreatefromjpeg($GET['img']); }else if ($src_size['mime']=== 'image/png'){ $src=imagecreatefrompng($GET['img']); }else if ($src_size['mime']=== 'image/gif'){ $src=imagecreatefromgif($GET['img']); } $src_aspect = round(($src_size[0] / $src_size[1]), 1); $thumb_aspect = round(($thumb_width /$thumb_height), 1); if($src_aspect < $thumb_aspect) { $new_size = array($thumb_width,($thumb_width / $src_size[0])* $src_size[1]); $src_pos =array(0,($new_size[1] - $thumb_height) /2); }else if($src_aspect > $thumb_aspect){ $newsize= array(($thumb_width / $src_size[1])* $src_size[0], $thumb_height); $src_pos =array(($new_size[0] - $thumb_width) /2, 0); }else{ $new_size =array($thumb_width, $thumb_height); $src_pos= array(0, 0); } if ($new_size[0] < 1) $new_size[0] = 1; if ($new_size[1] < 1) $new_size[1] = 1; $thumb =imagecreatetruecolor($thumb_width, $thumb_height); imagecopyresampled($thumb, $src, 0,0, $src_pos[0],$src_pos[1], $new_size[0],$new_size[1], $src_size[0], $src_size[1]); if ($src_size['mime'] === 'image/jpeg') { imagejpeg($thumb, "thumbs/{$_GET['img']}"); }else if ($src_size['mime'] === 'image/png'){ imagepng($thumb, "thumbs/{$_GET['img']}"); }else if ($src_size['mime'] === 'image/gif'){ imagegif($thumb, "thumbs/{$_GET['img']}"); } header("Location: thumbs/{$_GET['img']}"); } die(); } if(is_dir('./thumbs')===false){ mkdir('./thumbs', 0744); } $images = glob('*.{jpg,jpeg,gif,png}',GLOB_BRACE); ?> <html> <head> <meta http-equiv="Content Type" content="text/html; charset=utf=8" /> <style type="text/css"> a,img{float:left;} </style> <title>Image Gallery</title> </head> <body> <div> <?php foreach($images as $image) { if(file_exists("./thumbs/{$image}")) { echo "<a href=\"{$image}\"><img scr=\"thumbs/{$image}\" alt=\"{$image}\" /></a>"; }else{ echo "<a href=\"{$image}\"><img scr=\"?img={$image}\" alt=\"{$image}\" /></a>"; } } ?> </div> </body> </html>All i get when i run this code is the blue rectangles with the file name written in them, it seems the the thumbnail part
does'nt work. The code does create the the thumbs folder.
At this point(code below) the Betterphp video outputs the blue rectangles with the file name written in them, mine outputs nothing.
However i don't see anything wrong with this part of the code
if(is_dir('./thumbs')===false){ mkdir('./thumbs', 0744); } $images = glob('*.{jpg,jpeg,gif,png}',GLOB_BRACE); ?> <html> <head> <meta http-equiv="Content Type" content="text/html; charset=utf=8" /> <style type="text/css"> a,img{float:left;} </style> <title>Image Gallery</title> </head> <body> <div> <?php foreach($images as $image) { if(file_exists("./thumbs/{$image}")) { echo "<a href=\"{$image}\"><img scr=\"thumbs/{$image}\" alt=\"{$image}\" /></a>"; }else{ echo "<a href=\"{$image}\"><img scr=\"?img={$image}\" alt=\"{$image}\" /></a>"; } } ?> </div> </body>Thank you