A
A
Anton2016-09-05 17:44:31
Kohana
Anton, 2016-09-05 17:44:31

Kohana, photo uploader, changes photo extensions all to .jpg, how to keep extensions as they are?

Hello, I implemented a photo uploader for categories, I upload various photos with different extensions and it remakes them all into .png, how can I make sure that the extensions do not change, for example, so that .png remains as it is, and the rest can be .jpg were made.
My code:

public function _upload_img($file, $ext = null, $directory = null)
    {
        if ($directory == null)
        {
            $directory = 'media/uploads/cat';
            $smalldirectory = 'media/uploads/cat/small/';
            $admindirectory = 'media/uploads/cat/small/admin/';
        }
        if ($ext == null)
        {
            $ext = 'png';
        }
        // Генерируем случайное название
        $symbols = '0123456789abcdefghijklmnopqrstuvwxyz';
        $filename = '';
        for ($i = 0; $i < 10; $i++)
        {
            $filename .= rand(1, strlen($symbols));
        }

        $im = Image::factory($file);
        if ($im->width < 230 OR $im->height < 230)
        {
            return false;
        }
        else
        {
            $im->resize(800, 600);
            $im->save("$directory/$filename.$ext");
            
            $im = Image::factory($file);
            $im->resize(210, 184, Image::INVERSE);
            $im->crop(210, 184);
            $im->save("$smalldirectory/small_$filename.$ext");
            
            // Делает маленькую фотку для админки
            $im->resize(50, 50, Image::INVERSE);
            $im->save("$admindirectory/admin_$filename.$ext");
            
            return "$filename.$ext";
        }
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question