Restict Upload size of images
Posted: Sat Jun 03, 2006 3:55 am
Good Morning Team,
I have a problem in resticting the upload size for images, can anuone give any help please....
This is what I have so far for uploading images...
function ResizeConserveAspectRatio($source, $destination = NULL, $long_dimension = 100)
{
$w = $long_dimension;
$h = $long_dimension;
$source = @imagecreatefromstring(
@file_get_contents($source))
or die('Not a valid image format.');
$x = imagesx($source);
$y = imagesy($source);
if($w && ($x < $y)) $w = round(($h / $y) * $x); // maintain aspect ratio
else $h = round(($w / $x) * $y); // maintain aspect ratio
$slate = @imagecreatetruecolor($w, $h) or die('Invalid image dimmensions');
imagecopyresampled($slate, $source, 0, 0, 0, 0, $w, $h, $x, $y);
if(!$destination) header('Content-type: image/jpg');
@imagejpeg($slate, $destination, 100) or die('Directory permission problem');
imagedestroy($slate);
imagedestroy($source);
if(!$destination) exit; // return details about the thumbnail
return array($w,$h,'width="'.$w.'" height="'.$h.'"','mime'=>'image/jpg');
}
if (isset($_POST["op"]) && ($_POST["op"]=="photo"))
{
$fieldname = 'p_photo'; # as per your form
$PhotoNameTimeStamp = date("jnyHis");
$uploads_dir = 'uploads/';
$thumbs_dir = 'uploads/thumbs/';
$upload_size = 500; #pixels
$thumb_size = 75; # pixels
$filename = "" . $PhotoNameTimeStamp . ".jpg";
$thumb = $PhotoNameTimeStamp.'_t.jpg';
ResizeConserveAspectRatio($p_photo, $uploads_dir.$filename, $upload_size);
ResizeConserveAspectRatio($p_photo, $thumbs_dir.$thumb, $thumb_size);
echo "<img src=\"$uploads_dir/$filename\"><img src=\"$thumbs_dir/$thumb\">";
exit();
Best regards from Alan
I have a problem in resticting the upload size for images, can anuone give any help please....
This is what I have so far for uploading images...
function ResizeConserveAspectRatio($source, $destination = NULL, $long_dimension = 100)
{
$w = $long_dimension;
$h = $long_dimension;
$source = @imagecreatefromstring(
@file_get_contents($source))
or die('Not a valid image format.');
$x = imagesx($source);
$y = imagesy($source);
if($w && ($x < $y)) $w = round(($h / $y) * $x); // maintain aspect ratio
else $h = round(($w / $x) * $y); // maintain aspect ratio
$slate = @imagecreatetruecolor($w, $h) or die('Invalid image dimmensions');
imagecopyresampled($slate, $source, 0, 0, 0, 0, $w, $h, $x, $y);
if(!$destination) header('Content-type: image/jpg');
@imagejpeg($slate, $destination, 100) or die('Directory permission problem');
imagedestroy($slate);
imagedestroy($source);
if(!$destination) exit; // return details about the thumbnail
return array($w,$h,'width="'.$w.'" height="'.$h.'"','mime'=>'image/jpg');
}
if (isset($_POST["op"]) && ($_POST["op"]=="photo"))
{
$fieldname = 'p_photo'; # as per your form
$PhotoNameTimeStamp = date("jnyHis");
$uploads_dir = 'uploads/';
$thumbs_dir = 'uploads/thumbs/';
$upload_size = 500; #pixels
$thumb_size = 75; # pixels
$filename = "" . $PhotoNameTimeStamp . ".jpg";
$thumb = $PhotoNameTimeStamp.'_t.jpg';
ResizeConserveAspectRatio($p_photo, $uploads_dir.$filename, $upload_size);
ResizeConserveAspectRatio($p_photo, $thumbs_dir.$thumb, $thumb_size);
echo "<img src=\"$uploads_dir/$filename\"><img src=\"$thumbs_dir/$thumb\">";
exit();
Best regards from Alan