本文整理汇总了PHP中Image::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::delete方法的具体用法?PHP Image::delete怎么用?PHP Image::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image::delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setFlushImage
public function setFlushImage($flushImage = true)
{
if ($flushImage !== false and is_object($this->image)) {
$this->image->delete();
$this->image = null;
}
}
示例2: delPage
function delPage()
{
//Delete
if ($GLOBALS["action"] == "delete" && $GLOBALS["id"] != null) {
global $database;
$delpage = new Page("pages");
$id = $delpage::$id = "Id=" . $GLOBALS["id"];
$delpage->delete();
if ($database->affectedRows()) {
//delete corresponding image
$imgdirpath = "../";
$image_path = $imgdirpath . PAGEIMG_DIR;
$delimage = new Image("pageimgs");
$getimage = $delimage::findRow("Pageid='{$GLOBALS["id"]}'");
if ($database->getNumofRows() > 0) {
unlink($image_path . $getimage->Imgname . "." . $getimage->Extention);
//delete image
unlink($imgdirpath . TEMP_DIR . $getimage->Imgname . "." . $getimage->Extention);
//delete thumb image
$delimage::$id = "Id=" . $GLOBALS["id"];
$delimage->delete();
}
}
}
header("Location: " . filter_var($_SERVER['PHP_SELF'] . "?action=view&target=managepage"));
}
示例3: deleteAction
/**
* Apaga
*/
public function deleteAction()
{
$status = false;
if (isset($_POST)) {
if (isset($_REQUEST['id'])) {
$id = (int) $_REQUEST['id'];
$image = Image::find($id);
if ($image) {
$status = Image::delete($image->getId());
// Se a imagem foi apagada com sucesso realiza as demais ações
if ($status) {
// Apaga os tamanhos de imagem
$condition = sprintf("image_id = %s", $image->getId());
ImageSize::deleteAll($condition);
// Gerenciador de imagens
$imageManager = new ImageManager($image);
// Apaga o diretório das imagens
$imageManager->removeDir();
}
}
}
}
// Cria a variável flash
if ($status) {
$this->setFlash('notice_success', 'Image deleted successfully.');
} else {
$this->setFlash('notice_error', 'Delete image failed.');
}
// Redireciona para a listagem
$this->redirectTo('image', 'list');
}
示例4: destroyAction
public function destroyAction()
{
$this->logger->entering();
$this->logger->info('Quoting to protect against injection');
$where = $this->db->quoteInto('id = ?', $this->_getParam('id'));
$this->logger->info('Deleting the image');
$images = new Image();
$images->delete($where);
$this->logger->info('Redirecting to new image action');
$this->_redirect('image/new');
$this->logger->exiting();
}
示例5: deleteExpired
private static function deleteExpired()
{
if (is_writable(Image::PATH)) {
$query = 'select id from books where expired < now()';
$result = mysql_query($query);
while ($row = mysql_fetch_row($result)) {
$img = new Image($row[0]);
$img->delete();
}
}
$query = 'delete from books where expired < now()';
mysql_query($query);
}
示例6: testDelete
function testDelete()
{
$imageFull = Image::PATH . '0.png';
$imageThumb = Image::PATH . '0_thumb.png';
touch($imageFull);
touch($imageThumb);
$image = new Image(0);
$image->delete();
if (is_file($imageFull)) {
if (is_file($imageThumb)) {
unlink($imageThumb);
}
unlink($imageFull);
$this->fail("Image was not deleted.");
}
}
示例7: deleteImages
/**
* 删除所有产品图片
*
* @return bool success
*/
public function deleteImages()
{
$result = Db::getInstance()->getAll('
SELECT `id_image`
FROM `' . DB_PREFIX . 'product_to_image`
WHERE `id_product` = ' . (int) $this->id);
$deleted = array();
if ($result) {
foreach ($result as $row) {
$image = new Image($row['id_image']);
if ($image->delete()) {
$deleted[] = (int) $row['id_image'];
}
}
}
if (count($deleted) > 0) {
return Db::getInstance()->exec('DELETE FROM ' . DB_PREFIX . 'product_to_image WHERE id_image IN(' . implode(',', $deleted) . ')');
}
return false;
}
示例8: ajaxProcessDeleteProductImage
/**
* 删除图片并更新排序
* */
function ajaxProcessDeleteProductImage()
{
$res = true;
/* Delete product image */
$id_image = (int) Tools::Q('id_image');
$id_product = (int) Tools::Q('id_product');
$image = new Image($id_image);
if ($image->delete()) {
if (Db::getInstance()->exec('DELETE FROM ' . DB_PREFIX . 'product_to_image WHERE id_image=' . $id_image)) {
// update positions
$result = Db::getInstance()->getAll('
SELECT *
FROM `' . DB_PREFIX . 'product_to_image`
WHERE `id_product` = ' . $id_product . '
ORDER BY `position`
');
$i = 1;
if ($result) {
foreach ($result as $row) {
if ($row['id_image'] == $id_image && $row['cover'] == 1 && $i == 1) {
$row['cover'] = 1;
}
$row['position'] = $i++;
Db::getInstance()->update(DB_PREFIX . 'product_to_image', $row, '`id_image` = ' . (int) $row['id_image'], 1);
}
}
} else {
$res &= false;
}
} else {
$res &= false;
}
if ($res) {
die(json_encode(array('status' => 'ok', 'confirmations' => '操作成功!', 'content' => array('id' => $image->id))));
} else {
die(json_encode(array('status' => 'error', 'confirmations' => '删除文件失败!')));
}
}
示例9: array
} else {
$type = $_GET['type'];
}
$module_name = $type.'MediaGalleryModule';
$setting_data = array('middle' => array($module_name));
// deleting images
try {
if(isset($_GET['action']) && ($_GET['action']=='delete') && ($login_uid)) {
$id = $_GET['id'];
$type = $_POST['media_type'];
$album_id = $_POST['album_id'];
if ($_GET['type'] == 'image') {
$new_image = new Image();
$new_image->content_id = $id;
$new_image->delete($id);
$msg = 2004;
header("Location: $base_url/media_gallery.php?type=$type&msg_id=$msg&album_id=$album_id");
exit;
}
if ($_GET['type'] == 'audio') {
$new_image = new Audio();
$new_image->content_id = $id;
$new_image->delete($id);
$msg = 2005;
header("Location: $base_url/media_gallery.php?type=$type&msg_id=$msg&album_id=$album_id");
exit;
}
if ($_GET['type'] == 'video') {
示例10: manageDeclinatedImagesCRUD
/**
* Management of normal images CRUD
*
* @param boolean $filename_exists if the filename exists
* @param string $filename the image path
* @param array $imageSizes The
* @param string $directory
* @return boolean
*/
protected function manageDeclinatedImagesCRUD($filename_exists, $filename, $imageSizes, $directory)
{
switch ($this->wsObject->method) {
// Display the image
case 'GET':
case 'HEAD':
if ($filename_exists) {
$this->imgToDisplay = $filename;
} else {
throw new WebserviceException('This image does not exist on disk', array(61, 500));
}
break;
// Modify the image
// Modify the image
case 'PUT':
if ($filename_exists) {
if ($this->writePostedImageOnDisk($filename, null, null, $imageSizes, $directory)) {
$this->imgToDisplay = $filename;
return true;
} else {
throw new WebserviceException('Unable to save this image.', array(62, 500));
}
} else {
throw new WebserviceException('This image does not exist on disk', array(63, 500));
}
break;
// Delete the image
// Delete the image
case 'DELETE':
if ($filename_exists) {
// Delete products image in DB
if ($this->imageType == 'products') {
$image = new Image((int) $this->wsObject->urlSegment[3]);
return $image->delete();
} elseif (in_array($this->imageType, array('categories', 'manufacturers', 'suppliers', 'stores'))) {
$object = new $this->wsObject->resourceList[$this->imageType]['class']((int) $this->wsObject->urlSegment[2]);
return $object->deleteImage(true);
} else {
return $this->deleteImageOnDisk($filename, $imageSizes, $directory);
}
} else {
throw new WebserviceException('This image does not exist on disk', array(64, 500));
}
break;
// Add the image
// Add the image
case 'POST':
if ($filename_exists) {
throw new WebserviceException('This image already exists. To modify it, please use the PUT method', array(65, 400));
} else {
if ($this->writePostedImageOnDisk($filename, null, null, $imageSizes, $directory)) {
return true;
} else {
throw new WebserviceException('Unable to save this image', array(66, 500));
}
}
break;
default:
throw new WebserviceException('This method is not allowed', array(67, 405));
}
}
示例11: AddImage
private function AddImage($object, $url)
{
$shops = Shop::getShops(true, null, true);
$url = str_replace(' ', '%20', $url);
$image = new Image();
$image->id_product = (int) $object->id;
$image->position = Image::getHighestPosition($object->id) + 1;
$image->cover = 1;
// file_exists doesn't work with HTTP protocol
if (@fopen($url, 'r') == false) {
$error = true;
} else {
if (($field_error = $image->validateFields(false, true)) === true && ($lang_field_error = $image->validateFieldsLang(false, true)) === true && $image->add()) {
// associate image to selected shops
$image->associateTo($shops);
if (!self::copyImg($object->id, $image->id, $url)) {
$image->delete();
$this->errors[] = sprintf(Tools::displayError('Error copying image: %s'), $url);
}
} else {
$error = true;
}
}
}
示例12: attributeImportOne
protected function attributeImportOne($info, $default_language, &$groups, &$attributes, $regenerate, $shop_is_feature_active, $validateOnly = false)
{
AdminImportController::setDefaultValues($info);
if (!$shop_is_feature_active) {
$info['shop'] = 1;
} elseif (!isset($info['shop']) || empty($info['shop'])) {
$info['shop'] = implode($this->multiple_value_separator, Shop::getContextListShopID());
}
// Get shops for each attributes
$info['shop'] = explode($this->multiple_value_separator, $info['shop']);
$id_shop_list = array();
if (is_array($info['shop']) && count($info['shop'])) {
foreach ($info['shop'] as $shop) {
if (!empty($shop) && !is_numeric($shop)) {
$id_shop_list[] = Shop::getIdByName($shop);
} elseif (!empty($shop)) {
$id_shop_list[] = $shop;
}
}
}
if (isset($info['id_product']) && $info['id_product']) {
$product = new Product((int) $info['id_product'], false, $default_language);
} elseif (Tools::getValue('match_ref') && isset($info['product_reference']) && $info['product_reference']) {
$datas = Db::getInstance()->getRow('
SELECT p.`id_product`
FROM `' . _DB_PREFIX_ . 'product` p
' . Shop::addSqlAssociation('product', 'p') . '
WHERE p.`reference` = "' . pSQL($info['product_reference']) . '"
', false);
if (isset($datas['id_product']) && $datas['id_product']) {
$product = new Product((int) $datas['id_product'], false, $default_language);
}
} else {
return;
}
$id_image = array();
if (isset($info['image_url']) && $info['image_url']) {
$info['image_url'] = explode($this->multiple_value_separator, $info['image_url']);
if (is_array($info['image_url']) && count($info['image_url'])) {
foreach ($info['image_url'] as $key => $url) {
$url = trim($url);
$product_has_images = (bool) Image::getImages($this->context->language->id, $product->id);
$image = new Image();
$image->id_product = (int) $product->id;
$image->position = Image::getHighestPosition($product->id) + 1;
$image->cover = !$product_has_images ? true : false;
if (isset($info['image_alt'])) {
$alt = self::split($info['image_alt']);
if (isset($alt[$key]) && strlen($alt[$key]) > 0) {
$alt = self::createMultiLangField($alt[$key]);
$image->legend = $alt;
}
}
$field_error = $image->validateFields(UNFRIENDLY_ERROR, true);
$lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true);
if ($field_error === true && $lang_field_error === true && !$validateOnly && $image->add()) {
$image->associateTo($id_shop_list);
// FIXME: 2s/image !
if (!AdminImportController::copyImg($product->id, $image->id, $url, 'products', !$regenerate)) {
$this->warnings[] = sprintf($this->trans('Error copying image: %s', array(), 'Admin.Parameters.Notification'), $url);
$image->delete();
} else {
$id_image[] = (int) $image->id;
}
// until here
} else {
if (!$validateOnly) {
$this->warnings[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), isset($image->id_product) ? ' (' . $image->id_product . ')' : '');
}
if ($field_error !== true || $lang_field_error !== true) {
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . mysql_error();
}
}
}
}
} elseif (isset($info['image_position']) && $info['image_position']) {
$info['image_position'] = explode($this->multiple_value_separator, $info['image_position']);
if (is_array($info['image_position']) && count($info['image_position'])) {
foreach ($info['image_position'] as $position) {
// choose images from product by position
$images = $product->getImages($default_language);
if ($images) {
foreach ($images as $row) {
if ($row['position'] == (int) $position) {
$id_image[] = (int) $row['id_image'];
break;
}
}
}
if (empty($id_image)) {
$this->warnings[] = sprintf($this->trans('No image was found for combination with id_product = %s and image position = %s.', array(), 'Admin.Parameters.Notification'), $product->id, (int) $position);
}
}
}
}
$id_attribute_group = 0;
// groups
$groups_attributes = array();
if (isset($info['group'])) {
foreach (explode($this->multiple_value_separator, $info['group']) as $key => $group) {
//.........这里部分代码省略.........
示例13: fread
$userImage->setImageType('jpeg');
$userImage->scale(130, 170);
// Ordnerspeicherung
if ($gPreferences['profile_photo_storage'] == 1) {
$userImage->copyToFile(null, SERVER_PATH . '/adm_my_files/user_profile_photos/' . $getUserId . '_new.jpg');
} else {
// Foto in PHP-Temp-Ordner übertragen
$userImage->copyToFile(null, $_FILES['userfile']['tmp_name'][0]);
// Foto aus PHP-Temp-Ordner einlesen
$userImageData = fread(fopen($_FILES['userfile']['tmp_name'][0], 'r'), $_FILES['userfile']['size'][0]);
// Zwischenspeichern des neuen Fotos in der Session
$gCurrentSession->setValue('ses_binary', $userImageData);
$gCurrentSession->save();
}
// Image-Objekt löschen
$userImage->delete();
if ($getUserId == $gCurrentUser->getValue('usr_id')) {
$headline = $gL10n->get('PRO_EDIT_MY_PROFILE_PICTURE');
} else {
$headline = $gL10n->get('PRO_EDIT_PROFILE_PIC_FROM', $user->getValue('FIRST_NAME'), $user->getValue('LAST_NAME'));
}
// create html page object
$page = new HtmlPage($headline);
$page->addJavascript('$("#btn_cancel").click(function() {
self.location.href=\'' . $g_root_path . '/adm_program/modules/profile/profile_photo_edit.php?mode=dont_save&usr_id=' . $getUserId . '\';
});', true);
// show form
$form = new HtmlForm('show_new_profile_picture_form', $g_root_path . '/adm_program/modules/profile/profile_photo_edit.php?mode=save&usr_id=' . $getUserId, $page);
$form->addCustomContent($gL10n->get('PRO_CURRENT_PICTURE'), '<img class="imageFrame" src="profile_photo_show.php?usr_id=' . $getUserId . '" alt="' . $gL10n->get('PRO_CURRENT_PICTURE') . '" />');
$form->addCustomContent($gL10n->get('PRO_NEW_PICTURE'), '<img class="imageFrame" src="profile_photo_show.php?usr_id=' . $getUserId . '&new_photo=1" alt="' . $gL10n->get('PRO_NEW_PICTURE') . '" />');
$form->addLine();
示例14: attributeImport
public function attributeImport()
{
$default_language = Configuration::get('PS_LANG_DEFAULT');
$groups = array();
foreach (AttributeGroup::getAttributesGroups($default_language) as $group) {
$groups[$group['name']] = (int) $group['id_attribute_group'];
}
$attributes = array();
foreach (Attribute::getAttributes($default_language) as $attribute) {
$attributes[$attribute['attribute_group'] . '_' . $attribute['name']] = (int) $attribute['id_attribute'];
}
$this->receiveTab();
$handle = $this->openCsvFile();
AdminImportController::setLocale();
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
if (count($line) == 1 && empty($line[0])) {
continue;
}
if (Tools::getValue('convert')) {
$line = $this->utf8EncodeArray($line);
}
$info = AdminImportController::getMaskedRow($line);
$info = array_map('trim', $info);
AdminImportController::setDefaultValues($info);
if (!Shop::isFeatureActive()) {
$info['shop'] = 1;
} elseif (!isset($info['shop']) || empty($info['shop'])) {
$info['shop'] = implode($this->multiple_value_separator, Shop::getContextListShopID());
}
// Get shops for each attributes
$info['shop'] = explode($this->multiple_value_separator, $info['shop']);
$id_shop_list = array();
foreach ($info['shop'] as $shop) {
if (!is_numeric($shop)) {
$id_shop_list[] = Shop::getIdByName($shop);
} else {
$id_shop_list[] = $shop;
}
}
if (isset($info['id_product'])) {
$product = new Product((int) $info['id_product'], false, $default_language);
} else {
continue;
}
$id_image = null;
//delete existing images if "delete_existing_images" is set to 1
if (array_key_exists('delete_existing_images', $info) && $info['delete_existing_images'] && !isset($this->cache_image_deleted[(int) $product->id])) {
$product->deleteImages();
$this->cache_image_deleted[(int) $product->id] = true;
}
if (isset($info['image_url']) && $info['image_url']) {
$product_has_images = (bool) Image::getImages($this->context->language->id, $product->id);
$url = $info['image_url'];
$image = new Image();
$image->id_product = (int) $product->id;
$image->position = Image::getHighestPosition($product->id) + 1;
$image->cover = !$product_has_images ? true : false;
$field_error = $image->validateFields(UNFRIENDLY_ERROR, true);
$lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true);
if ($field_error === true && $lang_field_error === true && $image->add()) {
$image->associateTo($id_shop_list);
if (!AdminImportController::copyImg($product->id, $image->id, $url)) {
$this->warnings[] = sprintf(Tools::displayError('Error copying image: %s'), $url);
$image->delete();
} else {
$id_image = array($image->id);
}
} else {
$this->warnings[] = sprintf(Tools::displayError('%s cannot be saved'), isset($image->id_product) ? ' (' . $image->id_product . ')' : '');
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . mysql_error();
}
} elseif (isset($info['image_position']) && $info['image_position']) {
$images = $product->getImages($default_language);
if ($images) {
foreach ($images as $row) {
if ($row['position'] == (int) $info['image_position']) {
$id_image = array($row['id_image']);
break;
}
}
}
if (!$id_image) {
$this->warnings[] = sprintf(Tools::displayError('No image was found for combination with id_product = %s and image position = %s.'), $product->id, (int) $info['image_position']);
}
}
$id_attribute_group = 0;
// groups
$groups_attributes = array();
if (isset($info['group'])) {
foreach (explode($this->multiple_value_separator, $info['group']) as $key => $group) {
$tab_group = explode(':', $group);
$group = trim($tab_group[0]);
if (!isset($tab_group[1])) {
$type = 'select';
} else {
$type = trim($tab_group[1]);
}
// sets group
$groups_attributes[$key]['group'] = $group;
// if position is filled
//.........这里部分代码省略.........
示例15: cropCover
public function cropCover($id)
{
$top = \Input::get('top');
$failed = json_encode(['status' => 'error', 'message' => trans('photo.error', ['size' => formatBytes()])]);
$page = $this->pageRepository->get($id);
if (!$page or !$page->isOwner()) {
return $failed;
}
$image = $this->photo->cropImage(base_path($page->original_cover), 'cover/', 0, abs($top), 1000, 300, false);
$image = str_replace('%d', 'original', $image->result());
if (!empty($image)) {
/**
* Update user profile cover
*/
if ($page->cover and $page->cover != $page->original_cover) {
\Image::delete($page->cover);
}
$page->cover = $image;
$page->save();
return json_encode(['status' => 'success', 'url' => \Image::url($image)]);
} else {
return json_encode(['status' => 'error', 'message' => 'Error things']);
}
}