You are here

function theme_upload_element_preview in Upload element 6

Simple theming function to display the uploaded file.

Parameters

object $file File object:

Return value

string HTML of the filename and size.

File

./upload_element.module, line 388
A module that provides two new elements to the FAPI for file handling.

Code

function theme_upload_element_preview($element = NULL) {
  $label = t('Filename');
  $filename = '--';
  $filesize = '';
  $class = 'upload-element-preview';
  if ($file = _upload_element_parse_value($element)) {
    $filename = check_plain($file->filename);
    $filesize = '(' . format_size($file->filesize) . ')';

    // Add some nice mime type classes
    if ($file->filemime) {
      list($base_mime, $extended_mime) = explode('/', $file->filemime);
      $class = trim($class . ' mime-' . $base_mime . ' ' . ($extended_mime ? ' mime-' . $base_mime . '-' . $extended_mime : ''));
    }
  }
  return <<<END
      <div class="upload-element-file-description">
        <strong>{<span class="php-variable">$label</span>}: </strong>
        <span class="{<span class="php-variable">$class</span>}">{<span class="php-variable">$filename</span>} {<span class="php-variable">$filesize</span>}</span>
      </div>

END;
}