A
A
Anton2015-10-28 07:50:23
Kohana
Anton, 2015-10-28 07:50:23

Photo uploader, kohana, how to implement so that the extension does not change when uploading ??

Hello, when uploading a photo, if the picture is of a different type of extension like .png .gif, etc., the photo uploader processes the photo and makes it in
.jpg does.
Loader

public function _uplakcii_img($file, $ext = NULL, $directory = NULL)
    {

        if ($directory == NULL) {
            $directory = 'media/uploads/akcii/';
        }

        if ($ext == NULL) {
            $ext = 'jpg';
        }

        $symbols = '0123456789abcdefghijklmnopqrstuvwxyz';

        $filename = '';
        for ($i = 0; $i < 10; $i++) {
            $filename .= rand(1, strlen($symbols));
        }

        $im = Image::factory($file);
        if ($im->width < 50 OR $im->height < 50) {
            return false;
        } else {
            $im->save("$directory/$filename.$ext");
            return "$filename.$ext";
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2015-10-28
@R0dger

The file extension can be obtained through
already in the function itself or already feed it to the input.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question