Fileup
Fileup
jpg'; // create a new image from file $vir_img = @imagecreatefromjpeg($temp_file); break; case 'image/jpeg': $ext = '.jpeg'; // create a new image from file $vir_img = @imagecreatefromjpeg($temp_file); break; case 'image/png': $ext = '.png'; // create a new image from file $vir_img = @imagecreatefrompng($temp_file); break; case 'image/gif': $ext = '.gif'; // create a new image from file $vir_img = @imagecreatefromgif($temp_file); break; default: @unlink($temp_file); return; } $vir_img_arr['ext'] = $ext; $vir_img_arr['img'] = $vir_img; return $vir_img_arr; }
function uploadImageFile($filename ) { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $RandomStr = md5(microtime()); $strng = substr($RandomStr,0,5); $filename= $filename.'-'.$strng; /*Configuration part*/ //extract($_POST); $w = $_POST['w']; $h = $_POST['h']; $x1 = $_POST['x1']; $y1 = $_POST['y1']; $desired_width = 200; $desired_height = 200; $img_quality = 100; $year = date('Y'); $month = date('n'); $pathname = LEADIMG.'/'.$year.'/'; if (!is_dir($pathname))
{ mkdir($pathname,0777); $pathname = $pathname.$month.'/'; mkdir($pathname,0777); } else { $pathname = $pathname.$month.'/'; if (!is_dir($pathname )) mkdir($pathname,0777); } if ($_FILES) { $file = $_FILES['image_file']; if (! $file['error'] && $file['size'] < 350 * 1024) { if (is_uploaded_file($file['tmp_name'])) { $temp_file = $pathname.$filename; move_uploaded_file($file['tmp_name'], $temp_file); @chmod($temp_file, 0644); if (file_exists($temp_file) && filesize($temp_file) > 0) { $file_size_arr = getimagesize($temp_file); if (!$file_size_arr) { @unlink($temp_file); return; } $mime = $file_size_arr['mime']; $virtual_img_arr = $this->get_virtual_img($mime,$temp_fi le); $virtual_img = $virtual_img_arr[ 'img']; $virtual_img_ext = $virtual_img_ arr['ext']; if($w!=0) { $true_color_img = @imagecreatetruecolor( (int)$w, (int)$ h ); imagecopyresampled($true_color_img, $virtual_img, 0, 0, (int)$x1, (int)$y1, (int)$w, (int)$h, (int)$w, (int)$h); $result = $temp_file.'_thumb'. $virtual_img_ext; imagejpeg($true_color_img, $result, $img_quality); rename($temp_file,$temp_file.$virtua l_img_ext); return $year.'/'.$month.'/'.$filename. $virtual_img_ext ; } else { rename($temp_file,$temp _file.$virtual_img_ext); $this->set_thumb($filen ame."_thumb".$virtual_img_ext,$pathname,$pathname, $square_size=100, $quality=10 0); return $year.'/'.$mont h.'/'.$filename. $virtual_img_ext; }
} } } } } }