У меня проблема в браузере MI для мобильных устройств по умолчанию.Я написал код, который генерирует изображение png
с использованием функции php-gd
, а затем принудительно загружает его.код хорошо работает для Chrome, Mozilla, но не работает в браузере Mi.при нажатии кнопки загрузки в браузере MI файл загружается с именем файла, который генерирует изображение (т.е. downloadKey.php), а не сохраняется в расширении .png.
код, который я использую:
//Image init
$im = @imagecreatetruecolor(960, 1280)or die('Cannot Initialize new GD image stream');
//Colors init
//Background color
$white = imagecolorallocate($im, 255, 255, 255);
//$black = imagecolorallocate($im, 0, 0, 0);
//$blue = imagecolorallocate($im, 0, 0, 255);
$red = imagecolorallocate($im, 231, 76, 60);
//Foreground color
$color = $red;
//$color = imagecolorallocate($im, 231, 76, 60);
//Font init
$dir = $_SERVER['DOCUMENT_ROOT'] . '/myproject';
$font = $dir . '/fonts/timesbd.ttf';
//Project title
$heading = "My Project";
$height = 0;
$l = 0;
$m = 1;
$encoded = $_SESSION['encodedKey'];
$decryptedArray = unserialize(urldecode($encoded));
//Image creation
imagefilledrectangle($im, 0, 0, 959, 1279, $white);
imagettftext($im, 70, 0, 275, 150, $color, $font, $heading);
$arrayIndex = 0;
for ($i = 0; $i < 8; $i++) {
for ($j = 0, $width = 0; $j < 8; $j++, $width = $width + 100) {
$emoji = $key->getPattern($decryptedArray[$arrayIndex]);
$png = imagecreatefrompng($emoji);
imagecopyresampled($im, $png, 84 + $width, 250 + $height, 0, 0, 64, 64, 64, 64);
$arrayIndex = $arrayIndex + 1;
}
for ($k = 0, $width = 0; $k < 8; $k++, $width = $width + 100) {
imagettftext($im, 24, 0, 100 + $width, 340 + $height, $color, $font, sprintf("%02d", $m++));
}
$height += 120;
}
header("Content-Type: image/png");
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: Attachment; filename="test.png"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
imagepng($im);
imagedestroy($im);
имя файла: downloadKey.php