marketease Posted January 19, 2009 Share Posted January 19, 2009 I have a gallery that I am using called mg2 (http://www.minigal.dk/) that I like what it does except for one aspect. When uploading an image it keeps the original image on the server. I don't want large images saved though. I'm really new to php, so I'm not quite sure how to fix this. If anyone has any ideas on how to either remove the original after it makes a thumb and medium sized image, or resize the original so that it is at most 600px wide, that would help a lot. I believe the following section of code is where the problem lies. THANKS! function upload() { @set_time_limit(0); for ($x = 0; $x < 10; $x++) { if (!is_file("pictures/" . $_FILES["file" . $x]["name"])) { if ($_FILES["file". $x]["size"] > 0) { $fra = $_FILES["file" . $x]["tmp_name"]; $tempname = $_FILES["file" . $x]["name"]; $til = "pictures/" . $tempname; if (function_exists("move_uploaded_file")) { move_uploaded_file($fra, $til); } else { copy($fra, $til); } } } else if (filesize($_FILES["file" . $x]["name"]) != $_FILES["file". $x]["size"] && $_FILES["file". $x]["size"] > 0){ $file_parts = pathinfo('dir/' . $_FILES['file' . $x]['name']); $file_extension = strtolower($file_parts['extension']); $fra = $_FILES["file" . $x]["tmp_name"]; $tempname = $_FILES["file" . $x]["name"]; $til = str_replace("." . $file_extension,"",$tempname). "_autorenamed" . rand(1000,9999) . "." . $file_extension; if (function_exists("move_uploaded_file")) { move_uploaded_file($fra, $til); } else { copy($fra, $til); } } } $this->status = $this->lang['filesuploaded']; $this->log("Uploaded files"); include("skins/admin/admin2_status.php"); } function createthumb($filename) { $filename = "pictures/" . $filename; if(is_file($filename) && !is_file($this->thumb($filename))) { $dst_filename = $this->thumb($filename); $size = getimagesize($filename); $fileInfo = pathinfo($filename); $ext = strtolower($fileInfo["extension"]); $counter = 1; $max_width = "150"; $max_height = "150"; // IS MEDIUMSIZED PIC NEEDED if ($this->mediumimage > 0 && ($size[0] > ($this->mediumimage -100) || $size[1] > ($this->mediumimage-100))) { if (!is_file($this->medium($filename))) { $counter = 2; } } for ($i=1; $i <= $counter; $i++) { // MEDIUMDSIZED PICTURE SETTINGS if ($i == 2) { $dst_filename = $this->medium($filename); if ($size[0] > $size[1]) { $max_width = $this->mediumimage - 100; } else { $max_height = $this->mediumimage - 100; } } if ($ext == 'jpg' || $ext == 'jpeg') { $src_img = imagecreatefromjpeg($filename) or die( 'Cannot load input JPEG image' ); } else if ($ext == 'png') { $src_img = imagecreatefrompng($filename) or die( 'Cannot load input PNG image' ); } else if ($ext == 'gif') { $src_img = imagecreatefromgif($filename) or die( 'Cannot load input GIF image' ); } if ($size[0] > $size[1]) { $max_height = ($max_width/$size[0]) * $size[1]; } else { $max_width = ($max_height/$size[1]) * $size[0]; } if ($size[0] <= $max_width) $max_width = $size[0]; if ($size[1] <= $max_height) $max_height = $size[1]; $dst_img = imagecreatetruecolor($max_width, $max_height); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $max_width, $max_height, $size[0], $size[1]); imagejpeg($dst_img, $dst_filename, $this->thumbquality); imagedestroy($src_img); imagedestroy($dst_img); } } } Link to comment https://forums.phpfreaks.com/topic/141471-image-uploadhandling/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.