Elfinder: upload in another folder whit resize

Created on 1 Jul 2019  路  5Comments  路  Source: Studio-42/elFinder

i follow this link (i use laravel) and i use last version el-finder
https://github.com/Studio-42/elFinder/issues/1331
but not work !!

please see this config file for laravel elfinder
https://github.com/barryvdh/laravel-elfinder/blob/master/config/elfinder.php

it have 'options' i use it for bind

    'options' => array(
      'bind' => array(
          'upload.presave' => array('Plugin.AutoResize.onUpLoadPreSave'),
          'upload resize' => array(new App\genResize, 'smallImage'),
       ),
      'plugin' => array(
          'AutoResize' => array(
          'enable' => true,
          'maxWidth'  => 800,
          'quality' => 95
          )
      ),
    ),

and this my class

<?php
    namespace App;

        class genResize {

                function  smallImage($cmd, $result, $args, $elfinder, $volume) {
            // make image maxsize
            $maxWidth = 300;
            $maxHeight = 300;
            $jpgQuality = 70;

            $smallsDir = public_path('files/.smallSize') ;


            if ($volume && $result && isset($result['added'])) {
                foreach($result['added'] as $item) {



                    if ($file = $volume->file($item['hash'])) {
                        $path = $volume->getPath($item['hash']);
                        if (strpos($file['mime'], 'image/') === 0 && ($srcImgInfo = @getimagesize($path))) {
                            $zoom = min(($maxWidth/$srcImgInfo[0]),($maxHeight/$srcImgInfo[1]));
                            $width = round($srcImgInfo[0] * $zoom);
                            $height = round($srcImgInfo[1] * $zoom);
                            $tfp = tmpfile();
                            $info = stream_get_meta_data($tfp);
                            $temp = $info['uri'];
                            if ($src = fopen($path, 'rb')) {
                                stream_copy_to_stream($src, $tfp);
                                fclose($src);
                                if ($volume->imageUtil('resize', $temp, compact('width', 'height', 'jpgQuality'))) {
                                    @copy($temp, $smallsDir . '/' . $file['name']);
                                }
                            }
                        }
                    }
                }
            }
        }
}

but $volume is null and cant run continue ..

                                if ($volume->imageUtil('resize', $temp, compact('width', 'height', 'jpgQuality'))) {
                                    @copy($temp, $smallsDir . '/' . $file['name']);
                                }
question

Most helpful comment

please show full document create and resize in another path also change and remove from src image

All 5 comments

@vahidalvandi I tested with the standalone elFinder. $volume can be obtained correctly. You can also check out the standalone elFinder.

i tested it in laravel

how i can copy resize in another folder with same folder structure ?? my code copy it in root .small folder !

please show full document create and resize in another path also change and remove from src image

@vahidalvandi The code is copied with PHP's copy function so copy it wherever you want.

Was this page helpful?
0 / 5 - 0 ratings