HTML — Как я могу сжать файл изображения в PHP и сохранить в папке

В массиве $_FILES все отлично. Как мне сжать файл? Переменная $Buffer возвращается в формате base64.

Вот мой код:

$url = 'destination1.jpg';
$filename = compress_image($_FILES["uploadfile"]["tmp_name"], $url, 80);
$buffer = file_get_contents($url); /* Force download dialog... */
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download"); /* Don't allow caching... */
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); /* Set data type, size and filename */
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . strlen($buffer));
header("Content-Disposition: attachment; filename=$url"); /* Send our file... */
$buffer;

И функция compress_image выглядит так:

function compress_image($source_url, $destination_url, $quality)
{
$info = getimagesize($source_url);
if ($info['mime'] == 'image/jpeg') $image =
imagecreatefromjpeg($source_url);

elseif ($info['mime'] == 'image/gif') $image =
imagecreatefromgif($source_url);

imagejpeg($image, $destination_url, $quality);
// echo $destination_url;exit();
return $destination_url;
}

пожалуйста, помогите мне.

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector