thanks robc
<?php
//$username = strtolower($_POST['member_name']);
$username = "robc2236";
echo $username;
$images = glob("images/{$username}/*.{jpg,jpeg,,png,gif}",GLOB_BRACE);
if(isset($_GET['img']))
{
if(file_exists("images/{$username}/".$_GET['img']))
{
ignore_user_abort(true);
set_time_limit(120);
ini_set('memory_limit','512M');
$src_size = getimagesize("images/{$username}/".$_GET['img']);
if($src_size === false)
{
die('that does not look like an image.');
}
$thumb_width = 250;
$thumd_height = 200;
if($src_size['mime'] === 'image/jpeg')
{
$src = imagecreatefromjpeg("images/{$username}/".$_GET['img']);
}
else if($src_size['mime'] === 'image/png')
{
$src = imagecreatefrompng("images/{$username}/".$_GET['img']);
}
else if($src_size['mime'] === 'image/gif')
{
$src = imagecreatefromgif("images/{$username}/".$_GET['img']);
}
$src_aspect = round(($src_size[0]/$src_size[1]),1);
$thumb_aspect = round(($thumb_width / $thumd_height),1);
if($src_aspec<$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_aspec>$thumb_aspect )
{
$new_size = 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,"images/{$username}thumbs/{$_GET['img']}");
}
else if($src_size['mime'] === 'image/png')
{
echo"test";
imagepng($thumb,"images/{$username}/thumbs/{$_GET['img']}");
}
else if($src_size['mime'] === 'image/gif')
{
imagegif($thumb,"images/".$username."/thumbs/{$_GET['img']}");
}
header("Location: images/".$username."/thumbs/{$_GET['img']}");
}
die();
}
if(is_dir('images/'.$username.'/thumbs')===false)
{
mkdir('images/'.$username.'/thumbs',0744);
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Gallery</title>
</head>
<body>
<?php
//print_r($images);
foreach($images as $image)
{
if(file_exists("images/{$username}/thumbs/{$image}"))
{
echo "<a href=\"\"><img src=\"/images/{$username}/thumbs/{$image}\" alt=\"{$image}\"/></a>";
}
else
{
echo "<a href=\"\"><img src=\"?img=images/{$username}/{$image}\" alt=\"{$image}\"/></a>";
}
}
?>
</body>
</html>
