$num_newimages = $HTTP_POST_VARS['num_newimages']; $error = array(); for ($i = 1; $i <= $num_newimages; $i++) { $image_name = un_htmlspecialchars(trim($HTTP_POST_VARS['image_name_' . $i])); $cat_id = intval($HTTP_POST_VARS['cat_id_' . $i]); $user_id = intval($HTTP_POST_VARS['user_id_' . $i]) != 0 ? intval($HTTP_POST_VARS['user_id_' . $i]) : $user_info['user_id']; $remote_file = trim($HTTP_POST_VARS['remote_file_' . $i]); $remote_thumb_file = trim($HTTP_POST_VARS['remote_thumb_file_' . $i]); $image_download_url = trim($HTTP_POST_VARS['image_download_url_' . $i]); if ($image_name == "") { $error['image_name_' . $i] = 1; } if ($cat_id == 0) { $error['cat_id_' . $i] = 1; } if ((empty($HTTP_POST_FILES['file_' . $i]['tmp_name']) || $HTTP_POST_FILES['file_' . $i]['tmp_name'] == "none") && $remote_file == "" || $remote_file != "" && !check_remote_media($remote_file) && !check_local_media($remote_file)) { $error['file_' . $i] = 1; } if ($remote_thumb_file != "" && !check_remote_thumb($remote_thumb_file) && !check_local_thumb($remote_thumb_file)) { $error['remote_thumb_file_' . $i] = 1; } if ($image_download_url != "" && !is_remote($image_download_url) && !is_local_file($image_download_url)) { $error['image_download_url_' . $i] = 1; } if (!empty($additional_image_fields)) { foreach ($additional_image_fields as $key => $val) { if (isset($HTTP_POST_VARS[$key . '_' . $i]) && intval($val[2]) == 1 && trim($HTTP_POST_VARS[$key . '_' . $i]) == "") { $error[$key . '_' . $i] = 1; } } }
array_walk($image_keywords_arr, 'trim_value'); $image_keywords = implode(',', array_unique(array_filter($image_keywords_arr))); $image_active = isset($HTTP_POST_VARS['image_active']) && $HTTP_POST_VARS['image_active'] == 0 ? 0 : 1; $image_allow_comments = isset($HTTP_POST_VARS['image_allow_comments']) && $HTTP_POST_VARS['image_allow_comments'] == 0 ? 0 : 1; $image_download_url = isset($HTTP_POST_VARS['image_download_url']) ? format_url(un_htmlspecialchars(trim($HTTP_POST_VARS['image_download_url']))) : ""; $captcha = isset($HTTP_POST_VARS['captcha']) ? un_htmlspecialchars(trim($HTTP_POST_VARS['captcha'])) : ""; $direct_upload = check_permission("auth_directupload", $cat_id) ? 1 : 0; $upload_cat = $direct_upload ? $cat_id : 0; $error = 0; $uploaderror = 0; if ($cat_id == 0) { $error = 1; $field_error = preg_replace("/" . $site_template->start . "field_name" . $site_template->end . "/siU", str_replace(":", "", $lang['category']), $lang['field_required']); $msg .= ($msg != "" ? "<br />" : "") . $field_error; } if ((empty($HTTP_POST_FILES['media_file']['tmp_name']) || $HTTP_POST_FILES['media_file']['tmp_name'] == "none") && ($remote_media_file == "" || !check_remote_media($remote_media_file))) { $error = 1; $msg .= ($msg != "" ? "<br />" : "") . $lang['image_file_required']; } if ($image_name == "") { $error = 1; $field_error = preg_replace("/" . $site_template->start . "field_name" . $site_template->end . "/siU", str_replace(":", "", $lang['image_name']), $lang['field_required']); $msg .= ($msg != "" ? "<br />" : "") . $field_error; } if ($captcha_enable_upload && !captcha_validate($captcha)) { $msg .= ($msg != "" ? "<br />" : "") . $lang['captcha_required']; $error = 1; } if (!empty($additional_image_fields)) { foreach ($additional_image_fields as $key => $val) { if (isset($HTTP_POST_VARS[$key]) && intval($val[2]) == 1 && trim($HTTP_POST_VARS[$key]) == "") {
$error[$key] = 1; } } } if (!empty($HTTP_POST_FILES['file']['tmp_name']) && $HTTP_POST_FILES['file']['tmp_name'] != "none" && !$error) { unset($HTTP_POST_VARS['remote_file']); @rename(MEDIA_TEMP_PATH . "/" . $old_file_name, MEDIA_TEMP_PATH . "/" . $old_file_name . ".bak"); $new_name = $site_upload->upload_file("file", "media", 0); if (!$new_name) { $error_msg .= $lang['file_upload_error'] . ": <b>" . $HTTP_POST_FILES['file']['name'] . "</b><br />" . $site_upload->get_upload_errors(); @rename(MEDIA_TEMP_PATH . "/" . $old_file_name . ".bak", MEDIA_TEMP_PATH . "/" . $old_file_name); $error = 1; } else { $log[] = $lang['file_upload_success'] . ": <b>" . $new_name . "</b>"; } } elseif ((empty($HTTP_POST_FILES['file']['tmp_name']) || $HTTP_POST_FILES['file']['tmp_name'] == "none") && $remote_file != "" && check_remote_media($remote_file)) { $new_name = $remote_file; if (file_exists(MEDIA_TEMP_PATH . "/" . $old_file_name)) { unlink(MEDIA_TEMP_PATH . "/" . $old_file_name); } } else { $new_name = $old_file_name; } if ($delete_thumb_file == 1) { if (file_exists(THUMB_TEMP_PATH . "/" . $old_thumb_file_name)) { unlink(THUMB_TEMP_PATH . "/" . $old_thumb_file_name); } unset($HTTP_POST_VARS['remote_thumb_file']); $new_thumb_name = ""; } elseif (!empty($HTTP_POST_FILES['thumb_file']['tmp_name']) && $HTTP_POST_FILES['thumb_file']['tmp_name'] != "none" && !$error) { unset($HTTP_POST_VARS['remote_thumb_file']);