You are here

function dynamic_background_delete_image in Dynamic Background 7.2

Helper function that deletes a given image from the server and the database.

Parameters

int $fid: File id.

2 calls to dynamic_background_delete_image()
dynamic_background_admin_images_validate in includes/backgrounds.admin.inc
The administration images form validator form. It handles uploading the image and deletion if the checkbox is flaged.
dynamic_background_user_upload_form_submit in ./dynamic_background.module
Submission callback for user uploaded image, which stores the image(s) uploaded and stores the last uploaded image in the $form_state values info array. So extension automatically can activate the last uploaded image.

File

./dynamic_background.module, line 946
This module enables administrators to upload images used as background on the site. The selected background image link is exposed as either $background in the page.tpl file or as /background.css.

Code

function dynamic_background_delete_image($fid) {

  // Load file based on the fid.
  $file = file_load($fid);
  if ($file) {
    if (!file_delete($file, TRUE)) {
      throw new Exception(t('Could not delete %file from the system.', array(
        '%file' => $file->name,
      )));
    }
    else {

      // Delete from usage table.
      db_delete('dynamic_background_usage')
        ->condition('fid', $fid)
        ->execute();

      // Delete from images table.
      db_delete('dynamic_background_images')
        ->condition('fid', $fid)
        ->execute();
    }
  }
  else {
    throw new Exception(t('Could not delete from the system.'));
  }
}