You are here

function image_upload_element_preview_path in Upload element 6

This parses the session to pull out the filepath of the image.

Parameters

string $form_build_id The build id of the current form.:

string $name The key of the element.:

string $default A default image path to override the modules default image.:

Return value

object A file object, though the only property may be the filepath.

1 call to image_upload_element_preview_path()
image_upload_element_thumb in ./upload_element.pages.inc
Generates a temp image for image preview.

File

./upload_element.pages.inc, line 97
Handles image previews from both temperary and perminant file directories.

Code

function image_upload_element_preview_path($form_build_id, $name, $default = FALSE) {
  if (is_array($_SESSION['files']['upload_element'][$form_build_id])) {
    $files = $_SESSION['files']['upload_element'][$form_build_id];
    $file = isset($files[$name]) && is_object($files[$name]) ? $files[$name] : $files[$name . '_default'];
    if (is_object($file)) {
      if (!(isset($file->submit_action) && $file->submit_action == UPLOAD_ELEMENT_DELETE)) {
        return $file;
      }
    }
  }

  // This allows you to overwrite the default image
  $image = new stdClass();
  if ($default && image_get_info($default)) {
    $image->filepath = $default;
  }
  else {
    $image->filepath = drupal_get_path('module', 'upload_element') . '/no_image.gif';
  }
  return $image;
}