/** * insert_image * * * * * * */ function insert_image() { // check data was sent if (!isset($_POST)) { return 'no post data sent'; } if (!isset($_FILES)) { return 'no file data sent'; } // get default settings $config = get_settings('files'); // resize / upload image $image_file = $_FILES['image_file']; if (!empty($image_file['error'])) { return 'no image uploaded'; } else { if ($image_file['size'] > $config['files']['max_image_size']) { return 'image file is too large'; } $location = WW_ROOT . '/ww_files/images/'; // check posted width $width = isset($_POST['width']) ? (int) $_POST['width'] : 0; $width = $width > $config['files']['max_image_width'] ? $config['files']['max_image_width'] : $width; // check file width if (empty($width)) { list($o_width) = getimagesize($image_file['tmp_name']); $width = $o_width > $config['files']['max_image_width'] ? $config['files']['max_image_width'] : $width; } $image_data = resize_image($image_file, $location, '', $width); } // check image was uploaded if (!is_array($image_data)) { return $image_data; } // thumbnail? $th_location = WW_ROOT . '/ww_files/images/thumbs/'; if (isset($_FILES['thumb_file']) && empty($_FILES['thumb_file']['error'])) { $thumb_file = $_FILES['thumb_file']; resize_image($thumb_file, $th_location); } else { // generate a thumbnail $th_width = $config['files']['thumb_width']; resize_image($image_file, $th_location, '', $th_width); } // now we can finally insert into the database insert_image_details($image_data); return; }
} // update image details if (isset($_POST['update']) && $_POST['update'] == 'update details') { $image_id = (int) $_POST['image_id']; if (!empty($image_id)) { $update_status = update_image($image_id); if ($update_status == true) { header('Location: ' . $url); } else { $error = $update_status; } } } // insert image details - for rogue images if (isset($_POST['insert']) && $_POST['insert'] == 'insert details') { $insert_status = insert_image_details($_POST); if ($insert_status == true) { header('Location: ' . $_SERVER["PHP_SELF"] . '?page_name=images&image_id=' . $insert_status); } else { $error = $insert_status; } } // replace thumbnail if (isset($_POST['replace_thumb'])) { if (isset($_FILES['new_thumb']) && empty($_FILES['new_thumb']['error'])) { $location = WW_ROOT . '/ww_files/images/thumbs/'; $current = $_POST['current_thumb']; $new = $_FILES['new_thumb']; $th_replace_status = replace_file($location, $new, $current); if ($th_replace_status == true) { header('Location: ' . $url);