my code basically should crop the image to 219px by 127px and save the image to the database but im getting errors and cant figure it out.
<?php
if(isset($_POST['btnupload']) && $_FILES['imglogo']['size'] > 0) {
$tmpname = $_FILES['imglogo']['tmp_name'];
$imgsize = $security->secure($_FILES['imglogo']['size']);
$imgtype = $security->secure($_FILES['imglogo']['type']);
$school = $security->secure($_POST['school']);
//crop image
$canvas = imagecreatetruecolor(219,127);
$imgattrib = getimagesize($tmpname);
$source = imagecreatefromjpeg($tmpname);
imagecopyresized($canvas,$source,0,0,0,0,219,127,$imgattrib[0],$imgattrib[1]);
$handle = fopen($tmpname, "r");
$content = fread($handle, filesize($tmpname));
$content = addslashes($content);
fclose($handle);
$save = mysql_query("insert into tbl_school_preview values(null,'$school','$content','$imgtype','$imgsize')") or die(mysql_error());
//header("Location: school-catalog.php?page=school_preview");
}
?>
i dont see any errors but the crop isnt happending. do i have something wrong?
thnx
[updated code] here is the new peice of block for some reason the thumb wont save.
if(isset($_POST['btnupload']) && $_FILES['imglogo']['size'] > 0) {
//$filename = $security->secure($_FILES['imgschool']['name']);
$tmpname = $_FILES['imglogo']['tmp_name'];
$imgsize = $security->secure($_FILES['imglogo']['size']);
$imgtype = $security->secure($_FILES['imglogo']['type']);
$school = $security->secure($_POST['school']);
//crop image
$canvas = imagecreatetruecolor(219,127);
$imgattrib = getimagesize($tmpname);
$source = imagecreatefromjpeg($tmpname);
imagecopyresized($canvas,$source,0,0,0,0,219,127,$imgattrib[0],$imgattrib[1]);
$newfile = imagejpeg($canvas,'thumb.jpg',100);
$handle = fopen($newtmpfile, "r");
$content = fread($newtmpfile, filesize($newtmpfile));
$content = addslashes($content);
fclose($handle);
$save = mysql_query("insert into tbl_school_preview values(null,'$school','$content','$imgtype','$imgsize')") or die(mysql_error());