Initial commit,修正

This commit is contained in:
2025-07-13 19:37:38 +08:00
parent 38ce288e27
commit 65bbd06981
12384 changed files with 3985464 additions and 8 deletions
+57
View File
@@ -0,0 +1,57 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2019-01-12 12:13:35
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
class AttachController extends \yii\web\Controller
{
public $enableCsrfValidation = false; //取消csrf令牌验证;
//主界面
public function actionIndex()
{
$request = Yii::$app->request;
$get = $request->get();
$img = Urldecode($get['img']);
$file = Yii::getAlias("@upload").$img;
$img = file_get_contents($file);
$this->showImg($file);
}
/*
* php 页面直接输出图片
*/
function showImg($img){
$info = getimagesize($img);
$imgExt = image_type_to_extension($info[2], false); //获取文件后缀
$fun = "imagecreatefrom{$imgExt}";
$imgInfo = $fun($img); //1.由文件或 URL 创建一个新图象。如:imagecreatefrompng ( string $filename )
$mime = $info['mime'];
header('Content-Type:'.$mime);
$quality = 100;
if($imgExt == 'png') $quality = 9; //输出质量,JPEG格式(0-100),PNG格式(0-9)
$getImgInfo = "image{$imgExt}";
$getImgInfo($imgInfo, null, $quality); //2.将图像输出到浏览器或文件。如: imagepng ( resource $image )
//TBD: PNG图片会显示其被修改前的原始文件,与直接用SRC引用的方法有所不同
imagedestroy($imgInfo);
}
/*图片转换为 base64格式编码*/
function base64EncodeImage ($image_file) {
$base64_image = '';
$image_info = getimagesize($image_file);
$image_data = fread(fopen($image_file, 'r'), filesize($image_file));
$base64_image = 'data:' . $image_info['mime'] . ';base64,' . chunk_split(base64_encode($image_data));
return $base64_image;
}
}