function create_memdem_images($file) { global $genmem_settings; $image_ext = strtolower(strrchr($file, ".")); $image_res = @getimagesize(INFUSIONS . "al_genmem/asset/generators/originals/" . $file); $image_name = substr($file, 0, strrpos($file, ".")); $image_name_mem = filename_exists(INFUSIONS . "al_genmem/asset/generators/mems/", $image_name . $image_ext); $image_name_dem = filename_exists(INFUSIONS . "al_genmem/asset/generators/dems/", $image_name . ".jpg"); if ($image_ext == ".gif") { $filetype = 1; } elseif ($image_ext == ".jpg") { $filetype = 2; } elseif ($image_ext == ".png") { $filetype = 3; } if ($image_res[0] > $genmem_settings['mem_width'] || $image_res[1] > $genmem_settings['mem_height']) { createthumbnail($filetype, INFUSIONS . "al_genmem/asset/generators/originals/" . $file, INFUSIONS . "al_genmem/asset/generators/mems/" . $image_name_mem, $genmem_settings['mem_width'], $genmem_settings['mem_height']); } else { copy(INFUSIONS . "al_genmem/asset/generators/originals/" . $file, INFUSIONS . "al_genmem/asset/generators/mems/" . $image_name_mem); } $mem_res = @getimagesize(INFUSIONS . "al_genmem/asset/generators/mems/" . $image_name_mem); if ($mem_res[0] > $genmem_settings['mem_width'] - 2 * ($genmem_settings['dem_padding_side'] + $genmem_settings['dem_border'] + $genmem_settings['dem_after_border']) || $mem_res[1] > $genmem_settings['mem_height'] - $genmem_settings['dem_padding_bottom'] - $genmem_settings['dem_padding_top'] - 2 * ($genmem_settings['dem_border'] + $genmem_settings['dem_after_border'])) { $dem_preimage_width = $genmem_settings['mem_width'] - 2 * ($genmem_settings['dem_padding_side'] + $genmem_settings['dem_border'] + $genmem_settings['dem_after_border']); $dem_preimage_height = $genmem_settings['mem_height'] - $genmem_settings['dem_after_bottom'] - $genmem_settings['dem_padding_top'] - 2 * ($genmem_settings['dem_border'] + $genmem_settings['dem_after_border']); } else { $dem_preimage_width = $mem_res[0]; $dem_preimage_height = $mem_res[1]; } $dem_finalimage_width = $dem_preimage_width + 2 * ($genmem_settings['dem_padding_side'] + $genmem_settings['dem_border'] + $genmem_settings['dem_after_border']); $dem_finalimage_height = $dem_preimage_height + $genmem_settings['dem_padding_bottom'] + $genmem_settings['dem_padding_top'] + 2 * ($genmem_settings['dem_border'] + $genmem_settings['dem_after_border']); $dem_file = imagecreatetruecolor($dem_finalimage_width, $dem_finalimage_height); imagefill($dem_file, 0, 0, imagecolorallocate($dem_file, 0, 0, 0)); for ($i = 1; $i <= $genmem_settings['dem_border']; $i++) { imagerectangle($dem_file, $genmem_settings['dem_padding_side'] + $i, $genmem_settings['dem_padding_top'] + $i, $genmem_settings['dem_padding_side'] + 2 * ($genmem_settings['dem_border'] + $genmem_settings['dem_after_border']) + $dem_preimage_width - $i, $genmem_settings['dem_padding_top'] + 2 * ($genmem_settings['dem_border'] + $genmem_settings['dem_after_border']) + $dem_preimage_height - $i, imagecolorallocate($dem_file, 255, 255, 255)); } if ($filetype == 1) { $origimage = imagecreatefromgif(INFUSIONS . "al_genmem/asset/generators/mems/" . $image_name_mem); } elseif ($filetype == 2) { $origimage = imagecreatefromjpeg(INFUSIONS . "al_genmem/asset/generators/mems/" . $image_name_mem); } elseif ($filetype == 3) { $origimage = imagecreatefrompng(INFUSIONS . "al_genmem/asset/generators/mems/" . $image_name_mem); } imagecopyresized($dem_file, $origimage, $genmem_settings['dem_padding_side'] + $genmem_settings['dem_border'] + $genmem_settings['dem_after_border'] + 1, $genmem_settings['dem_padding_top'] + $genmem_settings['dem_border'] + $genmem_settings['dem_after_border'] + 1, 0, 0, $dem_preimage_width, $dem_preimage_height, $mem_res[0], $mem_res[1]); imagejpeg($dem_file, INFUSIONS . "al_genmem/asset/generators/dems/" . $image_name . ".jpg", 100); imagedestroy($dem_file); imagedestroy($origimage); return array("mem" => $image_name_mem, "dem" => $image_name_dem); }
chmod($dest . $file, 0644); unlink(DOWNLOADS . "submissions/" . $submit_criteria['download_file']); $download_file = $file; $download_url = ""; } if ($download_image) { $dest = DOWNLOADS . "images/"; $file = filename_exists($dest, $download_image); copy(DOWNLOADS . "submissions/images/" . $submit_criteria['download_image'], $dest . $file); chmod($dest . $file, 0644); unlink(DOWNLOADS . "submissions/images/" . $submit_criteria['download_image']); $download_image = $file; } if ($download_image_thumb) { $dest = DOWNLOADS . "images/"; $file = filename_exists($dest, $download_image_thumb); copy(DOWNLOADS . "submissions/images/" . $submit_criteria['download_image_thumb'], $dest . $file); chmod($dest . $file, 0644); unlink(DOWNLOADS . "submissions/images/" . $download_image_thumb); $download_image_thumb = $file; } $result = dbquery("INSERT INTO " . DB_DOWNLOADS . " SET\r\n\t\t\t\tdownload_user = '******'submit_user'] . "',\r\n\t\t\t\tdownload_title = '" . $download_title . "',\r\n\t\t\t\tdownload_description_short = '" . $download_description_short . "',\r\n\t\t\t\tdownload_description = '" . $download_description . "',\r\n\t\t\t\tdownload_image = '" . $download_image . "',\r\n\t\t\t\tdownload_image_thumb = '" . $download_image_thumb . "',\r\n\t\t\t\tdownload_url = '" . $download_url . "',\r\n\t\t\t\tdownload_file = '" . $download_file . "',\r\n\t\t\t\tdownload_cat = '" . $download_cat . "',\r\n\t\t\t\tdownload_license = '" . $download_license . "',\r\n\t\t\t\tdownload_copyright = '" . $download_copyright . "',\r\n\t\t\t\tdownload_homepage = '" . $download_homepage . "',\r\n\t\t\t\tdownload_os = '" . $download_os . "',\r\n\t\t\t\tdownload_version = '" . $download_version . "',\r\n\t\t\t\tdownload_filesize = '" . $download_filesize . "',\r\n\t\t\t\tdownload_allow_comments = '" . $download_allow_comments . "',\r\n\t\t\t\tdownload_allow_ratings = '" . $download_allow_ratings . "',\r\n\t\t\t\tdownload_datestamp = '" . time() . "',\r\n\t\t\t\tdownload_count = '0' ,'" . LANGUAGE . "'"); $result = dbquery("DELETE FROM " . DB_SUBMISSIONS . " WHERE submit_id='" . $_GET['submit_id'] . "'"); opentable($locale['630']); echo "<br /><div style='text-align:center'>" . $locale['631'] . "<br /><br />\n"; echo "<a href='" . FUSION_SELF . $aidlink . "'>" . $locale['402'] . "</a><br /><br />\n"; echo "<a href='index.php" . $aidlink . "'>" . $locale['403'] . "</a></div><br />\n"; closetable(); } else { redirect(FUSION_SELF . $aidlink); }
protected function verify_image_upload() { $locale = fusion_get_locale(); require_once INCLUDES . "infusions_include.php"; if ($this->field_config['multiple']) { $target_folder = $this->field_config['path']; $target_width = $this->field_config['max_width']; $target_height = $this->field_config['max_height']; $max_size = $this->field_config['max_byte']; $delete_original = $this->field_config['delete_original']; $thumb1 = $this->field_config['thumbnail']; $thumb2 = $this->field_config['thumbnail2']; $thumb1_ratio = 1; $thumb1_folder = $this->field_config['path'] . $this->field_config['thumbnail_folder'] . "/"; $thumb1_suffix = $this->field_config['thumbnail_suffix']; $thumb1_width = $this->field_config['thumbnail_w']; $thumb1_height = $this->field_config['thumbnail_h']; $thumb2_ratio = 0; $thumb2_folder = $this->field_config['path'] . $this->field_config['thumbnail_folder'] . "/"; $thumb2_suffix = $this->field_config['thumbnail2_suffix']; $thumb2_width = $this->field_config['thumbnail2_w']; $thumb2_height = $this->field_config['thumbnail2_h']; $query = ''; if (!empty($_FILES[$this->field_config['input_name']]['name']) && is_uploaded_file($_FILES[$this->field_config['input_name']]['tmp_name'][0]) && $this->safe()) { $result = array(); for ($i = 0; $i <= count($_FILES[$this->field_config['input_name']]['name']) - 1; $i++) { if (is_uploaded_file($_FILES[$this->field_config['input_name']]['tmp_name'][$i])) { $image = $_FILES[$this->field_config['input_name']]; $target_name = $_FILES[$this->field_config['input_name']]['name'][$i]; if ($target_name != "" && !preg_match("/[^a-zA-Z0-9_-]/", $target_name)) { $image_name = $target_name; } else { $image_name = stripfilename(substr($image['name'][$i], 0, strrpos($image['name'][$i], "."))); } $image_ext = strtolower(strrchr($image['name'][$i], ".")); $image_res = array(); if (filesize($image['tmp_name'][$i]) > 10 && @getimagesize($image['tmp_name'][$i])) { $image_res = @getimagesize($image['tmp_name'][$i]); } $image_info = array("image" => FALSE, "image_name" => $image_name . $image_ext, "image_ext" => $image_ext, "image_size" => $image['size'], "image_width" => $image_res[0], "image_height" => $image_res[1], "thumb1" => FALSE, "thumb1_name" => "", "thumb2" => FALSE, "thumb2_name" => "", "error" => 0); if ($image_ext == ".gif") { $filetype = 1; } elseif ($image_ext == ".jpg") { $filetype = 2; } elseif ($image_ext == ".png") { $filetype = 3; } else { $filetype = FALSE; } if ($image['size'][$i] > $max_size) { // Invalid file size $image_info['error'] = 1; } elseif (!$filetype || !verify_image($image['tmp_name'][$i])) { // Unsupported image type $image_info['error'] = 2; } elseif ($image_res[0] > $target_width || $image_res[1] > $target_height) { // Invalid image resolution $image_info['error'] = 3; } else { if (!file_exists($target_folder)) { mkdir($target_folder, 0755); } $image_name_full = filename_exists($target_folder, $image_name . $image_ext); $image_name = substr($image_name_full, 0, strrpos($image_name_full, ".")); $image_info['image_name'] = $image_name_full; $image_info['image'] = TRUE; move_uploaded_file($image['tmp_name'][$i], $target_folder . $image_name_full); if (function_exists("chmod")) { chmod($target_folder . $image_name_full, 0755); } if ($query && !dbquery($query)) { // Invalid query string $image_info['error'] = 4; if (file_exists($target_folder . $image_name_full)) { @unlink($target_folder . $image_name_full); } } elseif ($thumb1 || $thumb2) { require_once INCLUDES . "photo_functions_include.php"; $noThumb = FALSE; if ($thumb1) { if ($image_res[0] <= $thumb1_width && $image_res[1] <= $thumb1_height) { $noThumb = TRUE; $image_info['thumb1_name'] = $image_info['image_name']; $image_info['thumb1'] = TRUE; } else { if (!file_exists($thumb1_folder)) { mkdir($thumb1_folder, 0755, TRUE); } $image_name_t1 = filename_exists($thumb1_folder, $image_name . $thumb1_suffix . $image_ext); $image_info['thumb1_name'] = $image_name_t1; $image_info['thumb1'] = TRUE; if ($thumb1_ratio == 0) { createthumbnail($filetype, $target_folder . $image_name_full, $thumb1_folder . $image_name_t1, $thumb1_width, $thumb1_height); } else { createsquarethumbnail($filetype, $target_folder . $image_name_full, $thumb1_folder . $image_name_t1, $thumb1_width); } } } if ($thumb2) { if ($image_res[0] < $thumb2_width && $image_res[1] < $thumb2_height) { $noThumb = TRUE; $image_info['thumb2_name'] = $image_info['image_name']; $image_info['thumb2'] = TRUE; } else { if (!file_exists($thumb2_folder)) { mkdir($thumb2_folder, 0755, TRUE); } $image_name_t2 = filename_exists($thumb2_folder, $image_name . $thumb2_suffix . $image_ext); $image_info['thumb2_name'] = $image_name_t2; $image_info['thumb2'] = TRUE; if ($thumb2_ratio == 0) { createthumbnail($filetype, $target_folder . $image_name_full, $thumb2_folder . $image_name_t2, $thumb2_width, $thumb2_height); } else { createsquarethumbnail($filetype, $target_folder . $image_name_full, $thumb2_folder . $image_name_t2, $thumb2_width); } } } if ($delete_original && !$noThumb) { unlink($target_folder . $image_name_full); $image_info['image'] = FALSE; } } } } else { $image_info = array("error" => 5); } if ($image_info['error'] != 0) { $this->stop(); // return FALSE if possible switch ($image_info['error']) { case 1: // Invalid file size addNotice('danger', sprintf($locale['df_416'], parsebytesize($this->field_config['max_byte']))); self::setInputError($this->field_name); break; case 2: // Unsupported image type addNotice('danger', sprintf($locale['df_417'], ".gif .jpg .png")); self::setInputError($this->field_name); break; case 3: // Invalid image resolution addNotice('danger', sprintf($locale['df_421'], $this->field_config['max_width'], $this->field_config['max_height'])); self::setInputError($this->field_name); break; case 4: // Invalid query string addNotice('danger', $locale['df_422']); self::setInputError($this->field_name); break; case 5: // Image not uploaded addNotice('danger', $locale['df_423']); self::setInputError($this->field_name); break; } $result[$i] = $image_info; } else { $result[$i] = $image_info; } } // end for return $result; } else { return array(); } } else { if (!empty($_FILES[$this->field_config['input_name']]['name']) && is_uploaded_file($_FILES[$this->field_config['input_name']]['tmp_name']) && $this->safe()) { $upload = upload_image($this->field_config['input_name'], $_FILES[$this->field_config['input_name']]['name'], $this->field_config['path'], $this->field_config['max_width'], $this->field_config['max_height'], $this->field_config['max_byte'], $this->field_config['delete_original'], $this->field_config['thumbnail'], $this->field_config['thumbnail2'], 1, $this->field_config['path'] . $this->field_config['thumbnail_folder'] . "/", $this->field_config['thumbnail_suffix'], $this->field_config['thumbnail_w'], $this->field_config['thumbnail_h'], 0, $this->field_config['path'] . $this->field_config['thumbnail_folder'] . "/", $this->field_config['thumbnail2_suffix'], $this->field_config['thumbnail2_w'], $this->field_config['thumbnail2_h']); if ($upload['error'] != 0) { $this->stop(); switch ($upload['error']) { case 1: // Invalid file size addNotice('danger', sprintf($locale['df_416'], parsebytesize($this->field_config['max_byte']))); self::setInputError($this->field_name); break; case 2: // Unsupported image type addNotice('danger', sprintf($locale['df_417'], ".gif .jpg .png")); self::setInputError($this->field_name); break; case 3: // Invalid image resolution addNotice('danger', sprintf($locale['df_421'], $this->field_config['max_width'], $this->field_config['max_height'])); self::setInputError($this->field_name); break; case 4: // Invalid query string addNotice('danger', $locale['df_422']); self::setInputError($this->field_name); break; case 5: // Image not uploaded addNotice('danger', $locale['df_423']); self::setInputError($this->field_name); break; } return $upload; } else { return $upload; } } else { return array(); } } }
function upload_image($source_image, $target_name = "", $target_folder = IMAGES, $target_width = "1800", $target_height = "1600", $max_size = "150000", $delete_original = false, $thumb1 = true, $thumb2 = true, $thumb1_ratio = 0, $thumb1_folder = IMAGES, $thumb1_suffix = "_t1", $thumb1_width = "100", $thumb1_height = "100", $thumb2_ratio = 0, $thumb2_folder = IMAGES, $thumb2_suffix = "_t2", $thumb2_width = "400", $thumb2_height = "300", $query = "") { if (is_uploaded_file($_FILES[$source_image]['tmp_name'])) { $image = $_FILES[$source_image]; if ($target_name != "" && !preg_match("/[^a-zA-Z0-9_-]/", $target_name)) { $image_name = $target_name; } else { $image_name = stripfilename(substr($image['name'], 0, strrpos($image['name'], "."))); } $image_ext = strtolower(strrchr($image['name'], ".")); $image_res = @getimagesize($image['tmp_name']); $image_info = array("image" => false, "image_name" => $image_name . $image_ext, "image_ext" => $image_ext, "image_size" => $image['size'], "image_width" => $image_res[0], "image_height" => $image_res[1], "thumb1" => false, "thumb1_name" => "", "thumb2" => false, "thumb2_name" => "", "error" => 0, "query" => $query); if ($image_ext == ".gif") { $filetype = 1; } elseif ($image_ext == ".jpg") { $filetype = 2; } elseif ($image_ext == ".png") { $filetype = 3; } else { $filetype = false; } if ($image['size'] > $max_size) { // Invalid file size $image_info['error'] = 1; } elseif (!$filetype) { // Unsupported image type $image_info['error'] = 2; } elseif ($image_res[0] > $target_width || $image_res[1] > $target_height) { // Invalid image resolution $image_info['error'] = 3; } else { $image_name_full = filename_exists($target_folder, $image_name . $image_ext); $image_name = substr($image_name_full, 0, strrpos($image_name_full, ".")); $image_info['image_name'] = $image_name_full; $image_info['image'] = true; move_uploaded_file($image['tmp_name'], $target_folder . $image_name_full); if (function_exists("chmod")) { chmod($target_folder . $image_name_full, 0644); } if ($query && !dbquery($query)) { // Invalid query string $image_info['error'] = 4; unlink($target_folder . $image_name_full); } elseif ($thumb1 || $thumb2) { require_once INCLUDES . "photo_functions_include.php"; $noThumb = false; if ($thumb1) { if ($image_res[0] < $thumb1_width && $image_res[1] < $thumb1_height) { $noThumb = true; $image_info['thumb1_name'] = $image_info['image_name']; $image_info['thumb1'] = true; } else { $image_name_t1 = filename_exists($thumb1_folder, $image_name . $thumb1_suffix . $image_ext); $image_info['thumb1_name'] = $image_name_t1; $image_info['thumb1'] = true; if ($thumb1_ratio == 0) { createthumbnail($filetype, $target_folder . $image_name_full, $thumb1_folder . $image_name_t1, $thumb1_width, $thumb1_height); } else { createsquarethumbnail($filetype, $target_folder . $image_name_full, $thumb1_folder . $image_name_t1, $thumb1_width); } } } if ($thumb2) { if ($image_res[0] < $thumb2_width && $image_res[1] < $thumb2_height) { $noThumb = true; $image_info['thumb2_name'] = $image_info['image_name']; $image_info['thumb2'] = true; } else { $image_name_t2 = filename_exists($thumb2_folder, $image_name . $thumb2_suffix . $image_ext); $image_info['thumb2_name'] = $image_name_t2; $image_info['thumb2'] = true; if ($thumb2_ratio == 0) { createthumbnail($filetype, $target_folder . $image_name_full, $thumb2_folder . $image_name_t2, $thumb2_width, $thumb2_height); } else { createsquarethumbnail($filetype, $target_folder . $image_name_full, $thumb2_folder . $image_name_t2, $thumb2_width); } } } if ($delete_original && !$noThumb) { unlink($target_folder . $image_name_full); $image_info['image'] = false; } } } } else { // Image not uploaded $image_info = array("error" => 5); } return $image_info; }
unlink(DOWNLOADS . "submissions/" . $temp_file); } // move images if (!empty($callback_data['download_image']) && file_exists(DOWNLOADS . "/submissions/images/" . $callback_data['download_image'])) { $dest = DOWNLOADS . "images/"; $temp_file = $callback_data['download_image']; $callback_data['download_image'] = filename_exists($dest, $callback_data['download_image']); copy(DOWNLOADS . "submissions/images/" . $temp_file, $dest . $callback_data['download_image']); chmod($dest . $callback_data['download_image'], 0644); unlink(DOWNLOADS . "submissions/images/" . $temp_file); } // move thumbnail if (!empty($callback_data['download_image_thumb']) && file_exists(DOWNLOADS . "/submissions/images/" . $callback_data['download_image_thumb'])) { $dest = DOWNLOADS . "images/"; $temp_file = $callback_data['download_image_thumb']; $callback_data['download_image_thumb'] = filename_exists($dest, $callback_data['download_image_thumb']); copy(DOWNLOADS . "submissions/images/" . $temp_file, $dest . $callback_data['download_image_thumb']); chmod($dest . $callback_data['download_image_thumb'], 0644); unlink(DOWNLOADS . "submissions/images/" . $temp_file); } dbquery_insert(DB_DOWNLOADS, $callback_data, "save"); dbquery("DELETE FROM " . DB_SUBMISSIONS . " WHERE submit_id='" . intval($_GET['submit_id']) . "'"); addNotice("success", $locale['download_0063']); redirect(clean_request("", array("submit_id"), FALSE)); } } else { redirect(clean_request("", array("submit_id"), FALSE)); } } else { if (isset($_POST['delete']) && (isset($_GET['submit_id']) && isnum($_GET['submit_id']))) { $result = dbquery("\n\t\t\tSELECT ts.submit_id, ts.submit_datestamp, ts.submit_criteria\n\t\t\tFROM " . DB_SUBMISSIONS . " ts\n\t\t\tWHERE submit_type='d' and submit_id='" . intval($_GET['submit_id']) . "'\n\t\t");
$file_name = $callback_data['photo_filename']; $callback_data['photo_filename'] = filename_exists(IMAGES_G, $callback_data['photo_filename']); copy(INFUSIONS . "gallery/submissions/" . $file_name, IMAGES_G . $callback_data['photo_filename']); chmod(IMAGES_G . $callback_data['photo_filename'], 0644); unlink(INFUSIONS . "gallery/submissions/" . $file_name); } if (file_exists(INFUSIONS . "gallery/submissions/thumbs/" . $callback_data['photo_thumb1'])) { $file_name = $callback_data['photo_thumb1']; $callback_data['photo_thumb1'] = filename_exists(IMAGES_G_T, $callback_data['photo_thumb1']); copy(INFUSIONS . "gallery/submissions/thumbs/" . $file_name, IMAGES_G_T . $callback_data['photo_thumb1']); chmod(IMAGES_G_T . $callback_data['photo_thumb1'], 0644); unlink(INFUSIONS . "gallery/submissions/thumbs/" . $file_name); } if (file_exists(INFUSIONS . "gallery/submissions/thumbs/" . $callback_data['photo_thumb2'])) { $file_name = $callback_data['photo_thumb2']; $callback_data['photo_thumb2'] = filename_exists(IMAGES_G_T, $callback_data['photo_thumb2']); copy(INFUSIONS . "gallery/submissions/thumbs/" . $file_name, IMAGES_G_T . $callback_data['photo_thumb2']); chmod(IMAGES_G_T . $callback_data['photo_thumb2'], 0644); unlink(INFUSIONS . "gallery/submissions/thumbs/" . $file_name); } dbquery_insert(DB_PHOTOS, $callback_data, "save"); $result = dbquery("DELETE FROM " . DB_SUBMISSIONS . " WHERE submit_id='" . intval($_GET['submit_id']) . "'"); addNotice("success", $locale['gallery_0160']); redirect(clean_request("", array("submit_id"), FALSE)); } } else { redirect(clean_request("", array("submit_id"), FALSE)); } } else { if (isset($_POST['delete']) && (isset($_GET['submit_id']) && isnum($_GET['submit_id']))) { $result = dbquery("\n\t\t\tSELECT\n\t\t\tts.submit_id, ts.submit_datestamp, ts.submit_criteria\n\t\t\tFROM " . DB_SUBMISSIONS . " ts\n\t\t\tWHERE submit_type='p' and submit_id='" . intval($_GET['submit_id']) . "'\n\t\t");