本文整理匯總了PHP中gallery::get_image_new_name方法的典型用法代碼示例。如果您正苦於以下問題:PHP gallery::get_image_new_name方法的具體用法?PHP gallery::get_image_new_name怎麽用?PHP gallery::get_image_new_name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gallery
的用法示例。
在下文中一共展示了gallery::get_image_new_name方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: add_image
/**
* Add image to item
* @return void
* @param integer id of item
* @param string dir with images
*/
public function add_image($item, $dir)
{
// Check for user permission
if (user::is_got()) {
$this->set_title(Kohana::lang('gallery.add_image'));
$this->add_breadcrumb(Kohana::lang('gallery.add_image'), url::current());
// Set redirect URL
if (isset($_POST['redirect'])) {
$redirect = $_POST['redirect'];
} else {
$redirect = request::referrer();
}
$form = array('image' => '', 'redirect' => $redirect);
$errors = array();
if (isset($_FILES)) {
$files = new Validation($_FILES);
// Rules
$files->add_rules('image', 'upload::valid', 'upload::required', 'upload::type[jpg,jpeg]', 'upload::size[500K]');
if ($files->validate()) {
// Temporary file
$filename = upload::save('image');
// Get new name
$id = gallery::get_image_new_name($item, $dir);
// Save original and thumb
Image::factory($filename)->save('./data/' . $dir . '/' . $item . '_' . $id . '.jpg');
Image::factory($filename)->resize(128, 128, Image::AUTO)->quality(85)->save('./data/' . $dir . '/' . $item . '_' . $id . '_m.jpg');
// Remove the temporary file
unlink($filename);
url::redirect($form['redirect']);
} else {
// Repopulate form with error and original values
$form = arr::overwrite($form, $files->as_array());
$errors = $files->errors('gallery_errors');
}
}
// View
$this->template->content = new View('admin/add_image');
$this->template->content->errors = $errors;
$this->template->content->form = $form;
} else {
url::redirect('/denied');
}
}