Changeset 29124 for trunk/admin/include


Ignore:
Timestamp:
Jul 30, 2014, 3:48:35 PM (10 years ago)
Author:
plg
Message:

feature 3067: upload any file type with the new HTML5 upload form.

$file_types = confupload_form_all_types ? $conffile_ext : $confpicture_ext;

By default, confupload_form_all_types = false;

Location:
trunk/admin/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions_upload.inc.php

    r28714 r29124  
    220220
    221221    list($width, $height, $type) = getimagesize($source_filepath);
     222   
    222223    if (IMAGETYPE_PNG == $type)
    223224    {
     
    233234      $file_path.= 'tif';
    234235    }
     236    elseif (IMAGETYPE_JPEG == $type)
     237    {
     238      $file_path.= 'jpg';
     239    }
     240    elseif (isset($conf['upload_form_all_types']) and $conf['upload_form_all_types'])
     241    {
     242      $original_extension = strtolower(get_extension($original_filename));
     243
     244      if (in_array($original_extension, $conf['file_ext']))
     245      {
     246        $file_path.= $original_extension;
     247      }
     248      else
     249      {
     250        die('unexpected file type');
     251      }
     252    }
    235253    else
    236254    {
    237       $file_path.= 'jpg';
     255      die('forbidden file type');
    238256    }
    239257
     
    295313  }
    296314
     315  //
     316  // generate pwg_representative in case of video
     317  //
     318  $ffmpeg_video_exts = array( // extensions tested with FFmpeg
     319    'wmv','mov','mkv','mp4','mpg','flv','asf','xvid','divx','mpeg',
     320    'avi','rm',
     321    );
     322 
     323  if (isset($original_extension) and in_array($original_extension, $ffmpeg_video_exts))
     324  {
     325    $representative_file_path = dirname($file_path).'/pwg_representative/';
     326    $representative_file_path.= get_filename_wo_extension(basename($file_path)).'.';
     327   
     328    $representative_ext = 'jpg';
     329    $representative_file_path.= $representative_ext;
     330   
     331    prepare_directory(dirname($representative_file_path));
     332   
     333    $second = 1;
     334   
     335    $ffmpeg = $conf['ffmpeg_dir'].'ffmpeg';
     336    $ffmpeg.= ' -i "'.$file_path.'"';
     337    $ffmpeg.= ' -an -ss '.$second;
     338    $ffmpeg.= ' -t 1 -r 1 -y -vcodec mjpeg -f mjpeg';
     339    $ffmpeg.= ' "'.$representative_file_path.'"';
     340   
     341    // file_put_contents('/tmp/ffmpeg.log', "\n==== ".date('c')."\n".__FUNCTION__.' : '.$ffmpeg."\n", FILE_APPEND);
     342   
     343    @exec($ffmpeg);
     344
     345    if (!file_exists($representative_file_path))
     346    {
     347      $representative_ext = null;
     348    }
     349  }
     350
     351  if (isset($original_extension) and 'pdf' == $original_extension and pwg_image::get_library() == 'ext_imagick')
     352  {
     353    $representative_file_path = dirname($file_path).'/pwg_representative/';
     354    $representative_file_path.= get_filename_wo_extension(basename($file_path)).'.';
     355   
     356    $representative_ext = 'jpg';
     357    $representative_file_path.= $representative_ext;
     358
     359    prepare_directory(dirname($representative_file_path));
     360   
     361    $exec = $conf['ext_imagick_dir'].'convert';
     362    $exec.= ' -quality 98';
     363    $exec.= ' "'.realpath($file_path).'"[0]';
     364
     365    $dest = pathinfo($representative_file_path);
     366    $exec.= ' "'.realpath($dest['dirname']).'/'.$dest['basename'].'"';
     367    $exec.= ' 2>&1';
     368    @exec($exec, $returnarray);
     369  }
     370 
    297371  if (pwg_image::get_library() != 'gd')
    298372  {
     
    477551function is_valid_image_extension($extension)
    478552{
    479   return in_array(strtolower($extension), array('jpg', 'jpeg', 'png', 'gif'));
     553  global $conf;
     554 
     555  if (isset($conf['upload_form_all_types']) and $conf['upload_form_all_types'])
     556  {
     557    $extensions = $conf['file_ext'];
     558  }
     559  else
     560  {
     561    $extensions = $conf['picture_ext'];
     562  }
     563
     564  return array_unique(array_map('strtolower', $extensions));
    480565}
    481566
  • trunk/admin/include/photos_add_direct_prepare.inc.php

    r28919 r29124  
    9494  );
    9595
    96 $upload_file_types = 'jpeg, png, gif';
    97 
    98 if (pwg_image::get_library() == 'ext_imagick')
    99 {
    100   $upload_file_types.= ', tiff';
    101   $template->assign('tif_enabled', true);
    102 }
    103 
    104 if (false) // TODO manage zip files in pwg.images.upload
    105 {
    106   $upload_file_types.= ', zip';
    107 }
     96$unique_exts = array_unique(
     97  array_map(
     98    'strtolower',
     99    $conf['upload_form_all_types'] ? $conf['file_ext'] : $conf['picture_ext']
     100    )
     101  );
     102
    108103$template->assign(
    109104  array(
    110     'upload_file_types' => $upload_file_types,
     105    'upload_file_types' => implode(', ', $unique_exts),
     106    'file_exts' => implode(',', $unique_exts),
    111107    )
    112108  );
Note: See TracChangeset for help on using the changeset viewer.