Only one of the thumbnail images saves to the folder of this script even though several images are uploading. I'm thinking it must be something related to the iteration of the foreach loop. This is only the resizing script posted below. Does anyone have a quick fix? Thanks
define('THUMBS_DIR', 'C: /inetpub / wwwroot / mysite / images / thumbs / ');
define('MAX_WIDTH', 90);
define('MAX_HEIGHT', 100);
if (array_key_exists('upload', $_POST))
{
$original = $_FILES['image']['tmp_name'];
foreach ($original as $number => $tmp_file)
{
$original = ($tmp_file);
}
if (!$original)
{
echo 'NoImageSelected';
}
} else {
list($width, $height, $type) = getimagesize($original);
if ($width <= MAX_WIDTH && $height <= MAX_HEIGHT)
{
$ratio = 1;
} elseif ($width > $height) {
$ratio = MAX_WIDTH/$width;
} else {
$ratio = MAX_HEIGHT/$height;
}
$imagetypes = array(' / . gif$ / ',' / . jpg$ / ',' / . jpeg$ / ',' / . png$ / ');
$name = preg_replace($imagetypes, '', basename($file[$location]));
$moved = # move_uploaded_file($original[$location], THUMBS_DIR.$file);
if ($moved)
{
$result[] = $_FILES['image']['name'].'succesfullyuploaded';
$original = $ext.$file[$location];
}else{
$result = 'Problemuploading'.$_FILES['image']['name'];
}
if ($type == 1)
{
$source = imagecreatefromgif($original);
} elseif ($type == 2) {
$source = imagecreatefromjpeg($original);
} elseif ($type == 3) {
$source = imagecreatefrompng($original);
} else {
$result = 'Cannotidentifythefiletype';
}
}
Could you be more descriptive about what you want the script to do. I think your problem could be in :
$original = ($tmp_file);
You are overwriting the variable that you use in your foreach loop.
Related
I have set up a simple "Facebook" like timeline system for my friend to be able to upload statuses with images for his users to see. It seemed to all be working well although the file which stores the images keeps being deleted, and I can't seem to purposely cause the problem myself so I have no idea what is removing this directory?
I have added the upload/remove scripts below to see if anybody might be able to assist me here? I can't seem to find any part of the script which would delete the main image directory on its own?
PLEASE BARE IN MIND - This is still unfinished, and is nowhere near secure just yet, we are in testing phase and need to fix this problem before I can work on perfecting the system.
The main folder for storage of the images is post_images, this is the directory which is being deleted.
REMOVE DIR FUNCTION -
function rrmdir($dir) {
foreach(glob($dir . '/*') as $file) {
if(is_dir($file)) rrmdir($file); else unlink($file);
}
rmdir($dir);
}
DECLINE POSTS -
if(isset($_GET['decline_post'])){
$post_id = $conn->real_escape_string($_GET['decline_post']);
$getimagefolder = mysqli_fetch_assoc(mysqli_query($conn, "SELECT `post_image_folder` FROM `Pto6LsuQ_posts` WHERE `post_id` = '$post_id'"));
$image_folder = $getimagefolder['post_image_folder'];
mysqli_query($conn,"DELETE FROM `Pto6LsuQ_posts` WHERE `post_id` = '$post_id'");
$direc = 'post_images/'.$image_folder;
if (file_exists($direc)) {
rrmdir($direc);
} else {
}
header("Location: members_area.php");
}
DELETE POST -
if(isset($_GET['delete_post'])){
$post_id = $conn->real_escape_string($_GET['delete_post']);
$getimagefolder = mysqli_fetch_assoc(mysqli_query($conn, "SELECT `post_image_folder` FROM `Pto6LsuQ_posts` WHERE `post_id` = '$post_id'"));
$image_folder = $getimagefolder['post_image_folder'];
mysqli_query($conn,"DELETE FROM `Pto6LsuQ_posts` WHERE `post_id` = '$post_id'");
$direc = 'post_images/'.$image_folder;
if (file_exists($direc)) {
rrmdir($direc);
} else {
}
header("Location: members_area.php");
}
UPLOAD POST -
if(isset($_POST['new_post'])){
$post_status = $conn->real_escape_string($_POST['status']);
$user_id = $_SESSION['user_id'];
if(!empty($_FILES['images']['tmp_name'])){
$length = 9;
$search = true; // allow the loop to begin
while($search == true) {
$rand_image_folder = substr(str_shuffle("0123456789"), 0, $length);
if (!file_exists('../post_images/'.$rand_image_folder)) {
$search = false;
}
}
mkdir("../post_images/".$rand_image_folder);
foreach($_FILES['images']['tmp_name'] as $key => $tmp_name ){
$file_name = $key.$_FILES['images']['name'][$key];
$file_size = $_FILES['images']['size'][$key];
$file_tmp = $_FILES['images']['tmp_name'][$key];
$file_type = $_FILES['images']['type'][$key];
$check_file_type = substr($file_type, 0, strrpos( $file_type, '/'));
if($check_file_type !== 'image'){
header('Location: ../members_area.php?posterror=1');
}
$extensions = array("jpeg","jpg","png","JPEG","JPG","PNG");
$format = trim(substr($file_type, strrpos($file_type, '/') + 1));
if(in_array($format,$extensions) === false){
header('Location: ../members_area.php?posterror=1');
} else {
move_uploaded_file($file_tmp,"../post_images/".$rand_image_folder."/".$file_name);
$file = "../post_images/".$rand_image_folder."/".$file_name;
$cut_name = substr($file, strpos($file, "/") + 1);
$cut_name = explode('/',$cut_name);
$cut_name = end($cut_name);
$newfile = "../post_images/".$rand_image_folder."/thb_".$cut_name;
$info = getimagesize($file);
list($width, $height) = getimagesize($file);
$max_width = '350';
$max_height = '250';
//try max width first...
$ratio = $max_width / $width;
$new_width = $max_width;
$new_height = $height * $ratio;
//if that didn't work
if ($new_height > $max_height) {
$ratio = $max_height / $height;
$new_height = $max_height;
$new_width = $width * $ratio;
}
if ($info['mime'] == 'image/jpeg') $image = imagecreatefromjpeg($file);
elseif ($info['mime'] == 'image/gif') $image = imagecreatefromgif($file);
elseif ($info['mime'] == 'image/png') $image = imagecreatefrompng($file);
$image = imagecreatetruecolor($new_width, $new_height);
$photo = imagecreatefromjpeg($file);
imagecopyresampled($image, $photo, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image, $newfile, 70);
}
}
if($account_type < 4){
$post_public = 1;
} else {
$post_public = 0;
}
mysqli_query($conn,"INSERT INTO `Pto6LsuQ_posts`
(post_id,post_user_id,post_date_time,post_status,post_image_folder,post_likes,post_public_status)
VALUES ('','$user_id',NOW(),'$post_status','$rand_image_folder','0','$post_public')");
} else {
if($account_type < 4){
$post_public = 1;
} else {
$post_public = 0;
}
mysqli_query($conn,"INSERT INTO `Pto6LsuQ_posts`
(post_id,post_user_id,post_date_time,post_status,post_image_folder,post_likes,post_public_status)
VALUES ('','$user_id',NOW(),'$post_status','','0','$post_public')");
}
header('Location: ../members_area.php?posterror=2');
}
I'm trying to crop an image when it has been uploaded. So far I've only managed to resize it but if an image is a rectangular shape then the image is squashed which doesn't look nice. I'm trying to get coding that I can use with the function that I currently have to resize. The ones that I'm seeing I have to change my function and I'm hoping not to do that.
Here is my function
function createThumbnail($filename) {
global $_SITE_FOLDER;
//require 'config.php';
$final_width_of_image = 82;
$height = 85;
$path_to_image_directory = $_SITE_FOLDER.'portfolio_images/';
$path_to_thumbs_directory = $_SITE_FOLDER.'portfolio_images/thumbs/';
if(preg_match('/[.](jpg)$/', $filename)) {
$im = imagecreatefromjpeg($path_to_image_directory . $filename);
} 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 = floor($oy * ($final_width_of_image / $ox));
//$ny = $height;
$nm = imagecreatetruecolor($nx, $ny);
imagecopyresized($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;
}
Here is my function.
<?php
function crop($file_input, $file_output, $crop = 'square',$percent = false) {
list($w_i, $h_i, $type) = getimagesize($file_input);
if (!$w_i || !$h_i) {
echo 'Unable to get the length and width of the image';
return;
}
$types = array('','gif','jpeg','png');
$ext = $types[$type];
if ($ext) {
$func = 'imagecreatefrom'.$ext;
$img = $func($file_input);
} else {
echo 'Incorrect file format';
return;
}
if ($crop == 'square') {
$min = $w_i;
if ($w_i > $h_i) $min = $h_i;
$w_o = $h_o = $min;
} else {
list($x_o, $y_o, $w_o, $h_o) = $crop;
if ($percent) {
$w_o *= $w_i / 100;
$h_o *= $h_i / 100;
$x_o *= $w_i / 100;
$y_o *= $h_i / 100;
}
if ($w_o < 0) $w_o += $w_i;
$w_o -= $x_o;
if ($h_o < 0) $h_o += $h_i;
$h_o -= $y_o;
}
$img_o = imagecreatetruecolor($w_o, $h_o);
imagecopy($img_o, $img, 0, 0, $x_o, $y_o, $w_o, $h_o);
if ($type == 2) {
return imagejpeg($img_o,$file_output,100);
} else {
$func = 'image'.$ext;
return $func($img_o,$file_output);
}
}
?>
And you can call like this
crop($file_input, $file_output, $crop = 'square',$percent = false);
And also resize function if you need.
<?php
function resize($file_input, $file_output, $w_o, $h_o, $percent = false) {
list($w_i, $h_i, $type) = getimagesize($file_input);
if (!$w_i || !$h_i) {
return;
}
$types = array('','gif','jpeg','png');
$ext = $types[$type];
if ($ext) {
$func = 'imagecreatefrom'.$ext;
$img = $func($file_input);
} else {
return;
}
if ($percent) {
$w_o *= $w_i / 100;
$h_o *= $h_i / 100;
}
if (!$h_o) $h_o = $w_o/($w_i/$h_i);
if (!$w_o) $w_o = $h_o/($h_i/$w_i);
$img_o = imagecreatetruecolor($w_o, $h_o);
imagecopyresampled($img_o, $img, 0, 0, 0, 0, $w_o, $h_o, $w_i, $h_i);
if ($type == 2) {
return imagejpeg($img_o,$file_output,100);
} else {
$func = 'image'.$ext;
return $func($img_o,$file_output);
}
}
?>
resize($file_input, $file_output, $w_o, $h_o, $percent = false);
You can use SimpleImage class found here SimpleImage
[edit] Updated version with many more features here SimleImage Updated
I use this when resizing various images to a smaller thumbnail size while maintaining aspect ratio and exact image size output. I fill the blank area with a colour that suits the background for where the image will be placed, this class supports cropping. Explore the methods cutFromCenter and maxareafill.
For example in your code you would not need to imagecreatefromjpeg() you would simply;
Include the class include('SimpleImage.php');
then;
$im = new SimpleImage();
$im->load($path_to_image_directory . $filename);
$im->maxareafill($output_width,$output_height, 0,0,0); // rgb
$im->save($path_to_image_directory . $filename);
I use this class daily and find it very versatile.
<?
$start = $_GET[start] ? $_GET[start] : 0 ;
$sortby = $_COOKIE[sortby] ? $_COOKIE[sortby] : "name" ;
if($_GET[sortby]){
$sortby = $_GET[sortby];
setcookie("sortby", $_GET[sortby], time()+86400 );
header("location: index.php");
}
$od = opendir("./");
while($file = readdir($od)){
if( eregi("\.(gif|jpe?g|png)$", $file) ){
$file2 = rawurlencode($file);
$img_arr[$file2] = $file;
$img_arr_filesize[$file2] = filesize($file);
$img_arr_filemtime[$file2] = filemtime($file);
list($imagex, $imagey, $type, $attr) = getimagesize($file);
$img_arr_sizexy[$file2] = $imagex."x".$imagey;
}
}
asort($img_arr);
asort($img_arr_filesize);
asort($img_arr_filemtime);
switch($sortby){
case "time":
$img_arr_final = $img_arr_filemtime;
break;
case "size":
$img_arr_final = $img_arr_filesize;
break;
case "name":
$img_arr_final = $img_arr;
break;
}
$total_images = count($img_arr_final);
foreach($img_arr_final as $k=>$v){
$i++;
if($i < $start+1) continue;
if($i > $start + $pp) break;
$img_name = strlen($img_arr[$k]) > 18 ? substr($img_arr[$k],0,16)."..." :$img_arr[$k];
$alt = $img_arr[$k] . " -|- Last modified: " . date("Y-m-d H:i:s", $img_arr_filemtime[$k]) . " ";
$imgl .= "<div class=\"img_thumb\"><img src=\"index.php?thumb=$k\" alt=\"$alt\" title=\"$alt\" /><p title=\"".$img_arr[$k]."\"><strong>".$img_name. "</strong><br /><span class=\"mini\">".$img_arr_sizexy[$k].", ".round(($img_arr_filesize[$k]/1024))." KB</span></p></div>";
}
for($p=0; $p*$pp < $total_images ; $p++){
$active = ($p*$pp) == $start ? "active" : "" ;
$page_htmo .= "".($p+1)." ";
}
$arr_sortby = array("name"=>"Name", "size"=>"Size", "time"=>"Time");
foreach($arr_sortby as $k=>$v){
if($sortby == $k){
$sortby_html[] = "<strong>$v</strong>";
} else {
$sortby_html[] = "$v";
}
}
$sortby_htmo = implode(" | ", $sortby_html);
function make_thumbnail($updir, $img){
global $thumb_width, $thumb_height;
$thumbnail_width = $thumb_width ? $thumb_width : 120;
$thumbnail_height = $thumb_height ? $thumb_height : 80;
$arr_image_details = GetImageSize("$updir"."$img");
$original_width = $arr_image_details[0];
$original_height = $arr_image_details[1];
if( $original_width > $original_height ){
$new_width = $thumbnail_width;
$new_height = intval($original_height*$new_width/$original_width);
} else {
$new_height = $thumbnail_height;
$new_width = intval($original_width*$new_height/$original_height);
}
$dest_x = intval(($thumbnail_width - $new_width) / 2);
$dest_y = intval(($thumbnail_height - $new_height) / 2);
if($arr_image_details[2]==1) { $imgt = "ImageGIF"; $imgcreatefrom = "ImageCreateFromGIF"; $imgx = "gif"; }
if($arr_image_details[2]==2) { $imgt = "ImageJPEG"; $imgcreatefrom = "ImageCreateFromJPEG"; $imgx = "jpeg"; }
if($arr_image_details[2]==3) { $imgt = "ImagePNG"; $imgcreatefrom = "ImageCreateFromPNG"; $imgx = "png"; }
if( $imgt ) {
$old_image = $imgcreatefrom("$updir"."$img");
$new_image = ImageCreateTrueColor($thumbnail_width, $thumbnail_height);
imageCopyResized($new_image,$old_image,$dest_x,
$dest_y,0,0,$new_width,$new_height,$original_width,$original_height);
header("Content-Type: image/jpeg"); imagejpeg($new_image, NULL, 80);
}
}
if($_GET['thumb']) {
if( in_array($_GET['thumb'], $img_arr) ) make_thumbnail("./", $_GET['thumb']); // against file inclusion
exit();
}
?>
This is a gallery generator script, but it only shows me the pics when they are in the same directory as the script is in, how could I modify it to allow other scripts.
I've tried many tweaks but, nothing works.
It's almost certainly a file permissions issue as you're trying to open the root directory.
$od = opendir("./");
It will work for the directory that the script is in as the script will have permissions to access that directory.
I don't recommend giving PHP permission to access the root folder (even only in read mode) as it is a huge security risk, as theoretically someone could read your passwords file.
Instead you should use a non-root directory to hold the images you want to generate a gallery for and only give read permission to that, i.e.
mkdir /var/images
chmod a+r /var/images
I have a lot of images (500,000 +) in a folder on the server organized by date. I made a PHP script to copy and crop each JPG file on a subfolder (thumb), but it's very slow since PHP doesn't support multithreading.
I want advice on how to proceed. Is Python a good option for this? Is there a good tool, or how can I improve my resize function?
You can also take a look to my PHP Code
You can do it in PHP without any problem, simulating threads instead of using them directly. Actually, PHP doesn't have native threads (you can eventuallĀ„ use libraries but that's not very useful in your case).
In your code, instead of calling :
static::Crop($file,$destination,$tn_w = 300,$tn_h =200,$quality = 100,$wmsource = false);
Why not doing :
$array = array($file, $destination, $tn_w = 300, $tn_h = 200, $quality = 100, $wmsource = 0);
$command = "/usr/bin/php crop.php";
foreach ($array as $arg)
{
$command .= ' ' . escapeshellarg($arg);
}
exec("$command &"); // note the & which release your execution
usleep(100000);
And you put your cropping function inside crop.php, and then call it like :
list($exec, $file, $destination, $tn_w, $tn_h, $quality, $wmsource) = $argv;
static::Crop($file,$destination,$tn_w = 300,$tn_h =200,$quality = 100,$wmsource = false);
This will do the job.
You can also simulate mutexes using a file if you want to avoid usleep and control how many crops are running at once, that's really up to you. You definitely can do such work in PHP.
But php cgi support multithreading. Why not using exec()? Or you can use a shell script and for the conversion php cgi?
by Use This class
<?php
class thumbnail_images {
// get
var $PathImgOld;
var $PathImgNew;
var $NewWidth;
var $NewHeight;
// tmp
var $mime;
function imagejpeg_new ($NewImg,$path_img) {
if ($this->mime == 'image/jpeg' or $this->mime == 'image/pjpeg') imagejpeg($NewImg,$path_img);
elseif ($this->mime == 'image/gif') imagegif($NewImg, $path_img);
elseif ($this->mime == 'image/png') imagepng($NewImg, $path_img);
else return(false);
return(true);
}
function imagecreatefromjpeg_new($path_img) {
if ($this->mime == 'image/jpeg' or $this->mime == 'image/pjpeg') $OldImg = imagecreatefromjpeg($path_img);
elseif ($this->mime == 'image/gif') $OldImg = imagecreatefromgif($path_img);
elseif ($this->mime == 'image/png') $OldImg = imagecreatefrompng($path_img);
else return(false);
return($OldImg);
}
function create_thumbnail_images() {
$PathImgOld = $this->PathImgOld;
$PathImgNew = $this->PathImgNew;
$NewWidth = $this->NewWidth;
$NewHeight = $this->NewHeight;
$Oldsize = #getimagesize($PathImgOld);
$this->mime = $Oldsize['mime'];
$OldWidth = $Oldsize[0];
$OldHeight = $Oldsize[1];
if ($NewHeight == '' and $NewWidth != '') {
$NewHeight = ceil(($OldHeight * $NewWidth) / $OldWidth);
}
elseif ($NewWidth == '' and $NewHeight != '') {
$NewWidth = ceil(($OldWidth * $NewHeight) / $OldHeight);
}
elseif ($NewHeight == '' and $NewWidth == '') {
return(false);
}
$OldHeight_castr = ceil(($OldWidth * $NewHeight) / $NewWidth);
$castr_bottom = ($OldHeight - $OldHeight_castr) / 2;
$OldWidth_castr = ceil(($OldHeight * $NewWidth) / $NewHeight);
$castr_right = ($OldWidth - $OldWidth_castr) / 2;
if ($castr_bottom>0) {
$OldWidth_castr = $OldWidth;
$castr_right = 0;
}
elseif ($castr_right>0) {
$OldHeight_castr = $OldHeight;
$castr_bottom = 0;
}
else {
$OldWidth_castr = $OldWidth;
$OldHeight_castr = $OldHeight;
$castr_right = 0;
$castr_bottom = 0;
}
$OldImg = $this->imagecreatefromjpeg_new($PathImgOld);
if ($OldImg) {
$NewImg_castr = imagecreatetruecolor($OldWidth_castr, $OldHeight_castr);
if ($NewImg_castr) {
imagecopyresampled($NewImg_castr, $OldImg, 0, 0, $castr_right, $castr_bottom, $OldWidth_castr, $OldHeight_castr, $OldWidth_castr, $OldHeight_castr);
$NewImg = imagecreatetruecolor($NewWidth, $NewHeight);
if ($NewImg) {
imagecopyresampled($NewImg, $NewImg_castr, 0, 0, 0, 0, $NewWidth, $NewHeight, $OldWidth_castr, $OldHeight_castr);
imagedestroy($NewImg_castr);
imagedestroy($OldImg);
if (!$this->imagejpeg_new($NewImg, $PathImgNew)) return (false);
imagedestroy($NewImg);
}
}
}
else {
return(false);
}
return(true);
}
}
?>
Now use it
$width = $_REQUEST['img_width'];
$height = $_REQUEST['img_height'];
// example
$obj_img = new thumbnail_images();
$obj_img->PathImgOld = 'Old_image.jpg'; // Image for resize
$obj_img->PathImgNew = 'my_image_new_formSubURLkki.jpg'; // New Image Path
$obj_img->NewWidth = $width;
$obj_img->NewHeight = $height;
if (!$obj_img->create_thumbnail_images()) echo "error";
else {
echo 'Image Maked andsave in directory';
}
I use a image upload script which has stopped working now that my host has turned register_globals off. However, I don't know how do make it work without it. I'd be glad if you could help me out. Here's the code:
$uploadedfile = $_FILES['photo']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
// get the date from EXIF data
$exif = exif_read_data($uploadedfile, 0, true);
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
if ($name == 'DateTimeOriginal') {
$the_filename = explode(" ", $val);
$the_filenamedate = str_replace(":", "", $the_filename[0]);
$the_filenametime = str_replace(":", "", $the_filename[1]);
$newfilename = $the_filenamedate."-".$the_filenametime.".jpg";
$the_datetime = explode(" ", $val);
$the_date = str_replace(":", "-", $the_datetime[0]);
$the_time = $the_datetime[1];
$datetime = $the_date." ".$the_time;
$exif_db = 'y';
}
}
}
// use current date and time if no exif data
if (empty($newfilename)) {
$newfilename = date("Ymd-His").".jpg";
$datetime = date("Y-m-d H:i:s");
$exif_db = 'n';
}
// resize if necessary
list($width,$height) = getimagesize($uploadedfile);
if ($resize_it == 'y') {
if ($width > $maxwidth) {
$newwidth = $maxwidth;
$newheight = ($height/$width)*$newwidth;
} else {
$newwidth = $width;
$newheight = ($height/$width)*$newwidth;
}
} else {
$newwidth = $width;
$newheight = $height;
}
$tmp = imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$filename = $dirpath.$gal_id."/".$newfilename;
imagejpeg($tmp,$filename,100);
// create thumbnail
$uploadedthumb = $_FILES['photo']['tmp_name'];
$srcthumb = imagecreatefromjpeg($uploadedthumb);
list($widththumb,$heightthumb) = getimagesize($uploadedthumb);
if ($widththumb > $heightthumb) {
$newheightthumb = 100;
$newwidththumb = ($widththumb/$heightthumb)*$newheightthumb;
} elseif ($widththumb == $heightthumb) {
$newheightthumb = 100;
$newwidththumb = 100;
} elseif ($widththumb < $heightthumb) {
$newwidththumb = 100;
$newheightthumb = ($heightthumb/$widththumb)*$newwidththumb;
} else {
$newheightthumb = 100;
$newwidththumb = ($widththumb/$heightthumb)*$newheightthumb;
}
$tmpthumb = imagecreatetruecolor($newwidththumb,$newheightthumb);
imagecopyresampled($tmpthumb,$srcthumb,0,0,$src_top,$src_left,$newwidththumb,$newheightthumb,$widththumb,$heightthumb);
$thumbname = $dirpath.$gal_id."/zth_".$newfilename.".jpg";
imagejpeg($tmpthumb,$thumbname,100);
// free memory, destroying the source's and the pic's canvas
imagedestroy($srcthumb);
imagedestroy($tmpthumb);
imagedestroy($src);
imagedestroy($tmp);
Thanks in advance!
Use the $_POST array to read posted form fields. A field named emil will have the value in the PHP variable $_POST['emil'], not in $emil. You have to change all instances where you read form fields.
The same applies for variables in the querystring, which is now found in $_GET, cookies in $_COOKIE and session variables in $_SESSION.