Changeset 29761


Ignore:
Timestamp:
Sep 23, 2014, 3:16:15 PM (10 years ago)
Author:
plg
Message:

manage pwg_representative and keep original file extension (useful for videos, pdf, etc.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/virtualize/admin.php

    r17679 r29761  
    4646    path AS oldpath,
    4747    date_available,
     48    representative_ext,
    4849    id
    4950  FROM '.IMAGES_TABLE.'
     
    5960
    6061    $upload_dir = './upload/'.$year.'/'.$month.'/'.$day;
    61     if (!is_dir($upload_dir))
    62     {
    63       umask(0000);
    64       $recursive = true;
    65       if (!@mkdir($upload_dir, 0777, $recursive))
    66       {
    67         echo 'error during "'.$upload_dir.'" directory creation';
    68         exit();
    69       }
    70     }
    71     secure_directory($upload_dir);
     62    mkgetdir($upload_dir);
    7263
     64    $newfilename_wo_ext = $year.$month.$day.$hour.$minute.$second.'-'.substr($md5sum, 0, 8);
     65   
    7366    $extension = get_extension($row['oldpath']);
    74     $newfilename = $year.$month.$day.$hour.$minute.$second.'-'.substr($md5sum, 0, 8).'.jpg';
     67    $newfilename = $newfilename_wo_ext.'.'.$extension;
    7568
    7669    $newpath = $upload_dir.'/'.$newfilename;
    7770
    78     $query = '
     71    if (rename($row['oldpath'], $newpath))
     72    {
     73      if (!empty($row['representative_ext']))
     74      {
     75        $rep_dir = $upload_dir.'/pwg_representative';
     76        mkgetdir($rep_dir);
     77       
     78        $rep_oldpath = original_to_representative($row['oldpath'], $row['representative_ext']);
     79        rename($rep_oldpath, $rep_dir.'/'.$newfilename_wo_ext.'.'.$row['representative_ext']);
     80      }
     81
     82      $query = '
    7983UPDATE '.IMAGES_TABLE.'
    8084  SET path = \''.$newpath.'\',
     
    8286  WHERE id = '.$row['id'].'
    8387;';
    84     pwg_query($query);
     88      pwg_query($query);
    8589
    86     rename($row['oldpath'], $newpath);
    87     delete_element_derivatives(array('path' => $row['oldpath']));
     90      delete_element_derivatives(
     91        array(
     92          'path' => $row['oldpath'],
     93          'representative_ext' => $row['representative_ext'],
     94          )
     95        );
     96    }
    8897  }
    8998
Note: See TracChangeset for help on using the changeset viewer.