[go: up one dir, main page]

0% found this document useful (0 votes)
14 views3 pages

Fileup

The document describes functions for uploading image files and creating virtual images from uploaded files. It handles different image types, resizes images, and saves thumbnail versions.

Uploaded by

William Newton
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Fileup

The document describes functions for uploading image files and creating virtual images from uploaded files. It handles different image types, resizes images, and saves thumbnail versions.

Uploaded by

William Newton
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

function get_virtual_img($mime,$temp_file){ $vir_img_arr = array(); switch($mime) { case 'image/jpg': $ext = '.

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; }

} } } } } }

You might also like