0

I would like to use the following class to resize my image before storing it on my server: https://www.verot.net/php_class_upload.htm?lang=en-GB

I have image data stored in a MySQL table encoded as base64.

So far I've gotten this far:

$data = $myBase64DataFromDb;

//if (preg_match('/^data:image\/(\w+);base64,/', $data, $type)) {
//    $data = substr($data, strpos($data, ',') + 1);
//    $type = strtolower($type[1]); // jpg, png, gif
//    $data = base64_decode($data);

    $path = '/img/put/here/';

//    $filename = $data.'.'.$type;

//    $handle = new upload($filename);
    $handle = new upload($data);
    $handle->file_max_size = '5000000';

    $handle->image_resize = true;
    $handle->image_x = 600;
    $handle->image_ratio_y = true; 
    $handle->process($path);
    if ($handle->processed) {
        echo $filename;
        $handle->clean();
    } else {
        echo 'error : ' . $handle->error;
    }
// }

I keep getting error:

error : File not uploaded. Can't carry on a process.

What am I missing?

santa
  • 12,234
  • 49
  • 155
  • 255
  • In that class, `$_FILES` array is given to constructor for any further processes. You don't seem to do the same thing. – revo Jun 22 '18 at 22:13
  • @revo I've changed my code a bit to $handle = new upload($data); and am able to store the file but it is data.txt I need to figure out a way to convert it to .jpeg first now. Thanks – santa Jun 23 '18 at 13:50

0 Answers0