示例#1
0
 function save($temp_name, $field_name = false, $table = false, $id = false, $dir = false, $img_sizes = false, $field_name_n = false)
 {
     global $CFG;
     if ($temp_name) {
         $temp_name1 = $temp_name;
         $temp_name = $CFG->dirroot . $CFG->temp_file_location . $temp_name;
         $dir1 = $dir;
         $dir = $dir ? $CFG->dirroot . $dir : $CFG->dirroot . $CFG->default_upload_location;
         $dir = !stristr($dir, '/') ? $dir . '/' : $dir;
         $file_parts = explode('.', $temp_name);
         $ext = strtolower(end($file_parts));
         DB::saveImageSizes($field_name, $_REQUEST['image_sizes'][$field_name]);
         $image_sizes = DB::getImageSizes($field_name);
         if ($id) {
             $ext1 = in_array($ext, $CFG->accepted_image_formats) ? 'jpg' : $ext;
             $i = DB::insert($table . '_files', array('f_id' => $id, 'ext' => $ext1, 'dir' => $dir1, 'old_name' => $temp_name1, 'field_name' => $field_name));
             self::saveDescriptions($table, $field_name_n, $i);
             if (in_array($ext, $CFG->accepted_image_formats)) {
                 $ir = new ImageResize($temp_name, false, false, false);
                 if ($_REQUEST['crop_images'][$field_name]) {
                     $ir->setAutoCrop(true);
                 }
                 $ir->setHighQuality();
                 if (!is_array($img_sizes)) {
                     $ir->save($dir . $table . '_' . $id . '_' . $i . '.' . $ext1, 'jpeg', 90);
                     if ($_REQUEST['encrypt_files'][$field_name]) {
                         File::encrypt($dir . $table . '_' . $id . '_' . $i . '.' . $ext1);
                     }
                 } else {
                     foreach ($image_sizes as $key => $size) {
                         $ir->setSize($size['width'], $size['height']);
                         $ir->save($dir . $table . '_' . $id . '_' . $i . '_' . $key . '.' . $ext1, 'jpeg', 90);
                         if ($_REQUEST['encrypt_files'][$field_name]) {
                             File::encrypt($dir . $table . '_' . $id . '_' . $i . '_' . $key . '.' . $ext1);
                         }
                     }
                 }
                 @unlink($temp_name);
                 return true;
             } else {
                 if (rename($temp_name, $dir . $table . '_' . $id . '_' . $i . '.' . $ext)) {
                     if ($_REQUEST['encrypt_files'][$field_name]) {
                         File::encrypt($dir . $table . '_' . $id . '_' . $i . '.' . $ext);
                     }
                     return true;
                 }
             }
         } else {
             if (@rename($temp_name, $dir . $temp_name)) {
                 if ($_REQUEST['encrypt_files'][$field_name]) {
                     File::encrypt($dir . $dir . $temp_name);
                 }
                 return $dir . $temp_name;
             }
         }
     } else {
         return false;
     }
 }
示例#2
0
 function save($temp_name, $field_name = false, $table = false, $id = false, $dir = false, $img_sizes = false, $field_name_n = false)
 {
     global $CFG;
     if ($temp_name) {
         $temp_name1 = $temp_name;
         $temp_name = $CFG->dirroot . $CFG->temp_file_location . $temp_name;
         $dir1 = $dir;
         $dir = $dir ? $CFG->dirroot . $dir : $CFG->dirroot . $CFG->default_upload_location;
         $dir = !stristr($dir, '/') ? $dir . '/' : $dir;
         $file_parts = explode('.', $temp_name);
         $ext = strtolower(end($file_parts));
         if (!empty($_REQUEST['tokenizers'])) {
             unset($_REQUEST['tokenizers']);
         }
         DB::saveImageSizes($field_name, $_REQUEST['image_sizes'][$field_name]);
         $image_sizes = DB::getImageSizes($field_name);
         if ($id) {
             $ext1 = $ext;
             $i = DB::insert($table . '_files', array('f_id' => $id, 'ext' => $ext1, 'dir' => $dir1, 'old_name' => $temp_name1, 'field_name' => $field_name));
             self::saveDescriptions($table, $field_name_n, $i);
             if (in_array($ext, $CFG->accepted_image_formats)) {
                 $factory = new \ImageOptimizer\OptimizerFactory(array('ignore_errors' => false, 'jpegoptim_options' => array('--strip-all', '--all-progressive', '--max=75')), $logger);
                 $optimizer = $factory->get('jpegoptim');
                 $ir = new ImageResize($temp_name, false, false, false);
                 $ir->setHighQuality();
                 if ($_REQUEST['crop_images'][$field_name]) {
                     $ir->setAutoCrop(true);
                 }
                 if (!is_array($img_sizes)) {
                     $ir->save($dir . $table . '_' . $id . '_' . $i . '.' . $ext1, $ext1, 100);
                     $optimizer->optimize($dir . $table . '_' . $id . '_' . $i . '.' . $ext1);
                     if ($_REQUEST['encrypt_files'][$field_name]) {
                         File::encrypt($dir . $table . '_' . $id . '_' . $i . '.' . $ext1);
                     }
                 } else {
                     foreach ($image_sizes as $key => $size) {
                         $ir->setSize($size['width'], $size['height']);
                         $ir->save($dir . $table . '_' . $id . '_' . $i . '_' . $key . '.' . $ext1, 'jpeg', 100);
                         $optimizer->optimize($dir . $table . '_' . $id . '_' . $i . '_' . $key . '.' . $ext1);
                         if ($_REQUEST['encrypt_files'][$field_name]) {
                             File::encrypt($dir . $table . '_' . $id . '_' . $i . '_' . $key . '.' . $ext1);
                         }
                     }
                 }
                 unlink($temp_name);
                 return true;
             } else {
                 if (rename($temp_name, $dir . $table . '_' . $id . '_' . $i . '.' . $ext)) {
                     if ($_REQUEST['encrypt_files'][$field_name]) {
                         File::encrypt($dir . $table . '_' . $id . '_' . $i . '.' . $ext);
                     }
                     return true;
                 }
             }
         } else {
             if (rename($temp_name, $dir . $temp_name)) {
                 if ($_REQUEST['encrypt_files'][$field_name]) {
                     File::encrypt($dir . $dir . $temp_name);
                 }
                 return $dir . $temp_name;
             }
         }
     } else {
         return false;
     }
 }