PHP upload external function

PHP upload external function

yusaryusar Posts: 3Questions: 0Answers: 0

hi Allan,

i tried to use an external function to handle upload for resizing and create a thumbnail, then store the file information in my class variable as an array,

so i patch file Upload.php in function db something like this

public function db ( $table, $pkey, $fields )
    {
        $this->_dbTable = $table;
        $this->_dbPKey = $pkey;
        
        if(is_callable($fields)) {
            $this->_dbFields = $fields(); // this is my external upload handler call returning file info as an array
        } else {
            $this->_dbFields = $fields;
        }
        
        return $this;
    }

so in editor model class initialization it look like this

->fields(
    Field::inst( 'id' )
        ->upload( Upload::inst( function ($file, $id) { return $id; })
        ->db( 'files_table', 'id', function() {
            $model_class->upload_and_resize(); // external function for resize and thumbnail
            return $model_class->file_info; // file info after resizing
        })

can you tell me is there a better way to do this?
forgive me for my bad english

regards

Replies

  • allanallan Posts: 63,889Questions: 1Answers: 10,530 Site admin

    Its a clever idea that - it wasn't really the way I had thought of the db() method being used. I had intended that to be used only for database fields and a custom upload action would be used for the resizing action if required.

    Allan

  • yusaryusar Posts: 3Questions: 0Answers: 0

    yes, i already tried with custom upload action but then im having trouble inserting correct file name into database because the record already populated before resizing the image

    btw, can i link my account with another account which already purchase Editor license? this happen because my company purchase Editor license with my company account

    thanks Allan

  • allanallan Posts: 63,889Questions: 1Answers: 10,530 Site admin

    That's correct - you would need to write the information into the database directly in the upload method if you go that way.

    Regarding the Editor license - not a problem, could you drop me an e-mail (allan @ thisDomain.net) with the invoice number so I make sure I assign the correct license!

    Regards,
    Allan

This discussion has been closed.