function imagepicker_image_delete in Image Picker 5.2
Same name and namespace in other branches
- 5 imagepicker.module \imagepicker_image_delete()
- 6.2 imagepicker.functions.inc \imagepicker_image_delete()
- 7 imagepicker.functions.inc \imagepicker_image_delete()
5 calls to imagepicker_image_delete()
- imagepicker_admin_images in ./
imagepicker.module - imagepicker_admin_image_form_submit in ./
imagepicker.module - imagepicker_image_form_submit in ./
imagepicker.module - Submit image form
- imagepicker_user_image_form_submit in ./
imagepicker.module - Submit form
- imagepicker_user_page in ./
imagepicker.module - Account functions
File
- ./
imagepicker.module, line 759 - Enables permitted roles to upload images for insertion into configured nodes.
Code
function imagepicker_image_delete($img_id, $account = FALSE, $src = 'iframe') {
if ($account) {
$user = $account;
$userdir = array(
'name' => $user->name,
'uid' => $user->uid,
);
}
else {
global $user;
$userdir = TRUE;
}
if ($src == 'account') {
$outpath = 'user/' . $user->uid . '/imagepicker/images/browse';
}
elseif ($src == 'admin') {
$outpath = 'admin/settings/imagepicker/images/user/' . $user->uid . '/browse';
}
else {
$outpath = 'imagepicker/browse';
}
$img = _imagepicker_get_img($img_id, $src == 'admin' ? FALSE : TRUE, $account ? $user : FALSE);
if ($img) {
$destination = imagepicker_get_path(FALSE, $userdir);
$thumbsdir = $destination . IMAGEPICKER_THUMBS_DIR . DIRECTORY_SEPARATOR;
$browserdir = $destination . IMAGEPICKER_BROWSER_DIR . DIRECTORY_SEPARATOR;
file_delete($destination . $img['img_name']);
file_delete($thumbsdir . $img['img_name']);
file_delete($browserdir . $img['img_name']);
if (db_query("DELETE FROM {imagepicker} WHERE uid = %d AND img_id = %d", array(
$user->uid,
$img_id,
))) {
// groups entries
db_query("DELETE FROM {imagepicker_group_images} WHERE img_id = %d", array(
$img_id,
));
drupal_set_message(t('Image was successfully deleted'));
}
else {
drupal_set_message(t('Error while trying to delete your image from database.'), 'error');
}
}
else {
drupal_set_message(t('Image not found.'), 'error');
}
drupal_goto($outpath);
}