|

分享源码
界面截图: |
- |
是否带模块: |
- |
备注说明: |
- |
本帖最后由 芷新 于 2025-7-21 10:56 编辑
留作备用 以前弄过找不到了 有用到的可以下载
|
上传图片_获得外链wj100 | 逻辑型 | | |
传递指针 | 整数型 | | | |
变量名 | 类 型 | 静态 | 数组 | 备 注 | 图片路径 | 文本型 | | | 文件名 | 文本型 | | | 数据 | 字节集 | | | 响应 | 文本型 | | | json | 类_json | | | 局_外链 | 文本型 | | | 局_code | 文本型 | | | 局_msg | 文本型 | | | 局_time | 文本型 | | | 局_链接 | 文本型 | | | 局_结果 | 字节集 | | | 局_返回 | 文本型 | | | 局_文件名 | 文本型 | | | 局_图宽 | 文本型 | | | 局_图高 | 文本型 | | | 局_微缩图 | 文本型 | | |
图片路径 = 指针到文本 (传递指针 ) 文件名 = 取文本右边 (图片路径, 取文本长度 (图片路径 ) - 倒找文本 (图片路径, “\”, , 假)) 数据 = 到字节集 ( #常量1 )数据 = 子字节集替换 (数据, 到字节集 (“文件名”), 到字节集 (文件名 ), , )数据 = 子字节集替换 (数据, 到字节集 (“路径”), 读入文件 (图片路径 ), , )局_结果 = 网页_访问_对象 (“http://*****”, 1, , , , “Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryYTwvlk5brGmyD3Mn”, , , 真, 数据, , , , , , , , , )局_返回 = 到文本 (编码_编码转换对象 (局_结果 )) 调试输出 (局_返回 )json. 解析 (局_返回 )局_code = json. 取属性 (“code”). 取数据文本 ()局_msg = json. 取通用属性 (“msg”)局_time = json. 取通用属性 (“time”)局_链接 = json. 取通用属性 (“data.src”)局_文件名 = json. 取通用属性 (“data.name”)局_图宽 = json. 取属性 (“data.width”). 取数据文本 ()局_图高 = json. 取属性 (“data.height”). 取数据文本 ()局_微缩图 = json. 取通用属性 (“data.thumbsrc”) 调试输出 (局_code, 局_链接 ) 如果 (局_code = “1”) 运行状态.状态 = 局_msg  运行状态.图片链接 = 局_链接  运行状态.微缩图 = 局_微缩图 返回 (真)   运行状态.状态 = 局_msg  运行状态.图片链接 = 局_链接  运行状态.微缩图 = 局_微缩图 返回 (假)
好像上传不了附件
[PHP] 纯文本查看 复制代码 <?php
$imgurl = "http://*****/";
$info = $_POST['info'];
$time = date("Y-m-d H:i:s");
$max_file_size = 5000000; // 5MB
$destination_folder = "xianbao/";
$watermark = 0; // 水印开关
$waterstring = "Alidll";
$imgpreview = 1; // 是否生成预览图
// 支持的上传类型
$uptypes = array(
'image/jpg', 'image/jpeg', 'image/png', 'image/pjpeg', 'image/gif',
'image/bmp', 'image/x-png'
);
// 指定尺寸
$targetWidth = 800;
$targetHeight = 600;
// 缩略图尺寸
$thumbWidth = 200;
$thumbHeight = 150;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (!is_uploaded_file($_FILES["upfile"]["tmp_name"])) {
$arr = array('code' => 10, 'msg' => '图片不存在', 'time' => $time);
echo json_encode($arr);
exit;
}
$file = $_FILES["upfile"];
if ($max_file_size < $file["size"]) {
$arr = array('code' => 11, 'msg' => '文件太大', 'time' => $time);
echo json_encode($arr);
exit;
}
if (!in_array($file["type"], $uptypes)) {
$arr = array('code' => 12, 'msg' => '文件类型不符', 'time' => $time);
echo json_encode($arr);
exit;
}
if (!file_exists($destination_folder)) {
mkdir($destination_folder, 0777, true);
}
$pinfo = pathinfo($file["name"]);
$ftype = strtolower($pinfo['extension']);
$destination = $destination_folder . time() . "." . $ftype;
if (file_exists($destination)) {
$arr = array('code' => 13, 'msg' => '同名文件已存在', 'time' => $time);
echo json_encode($arr);
exit;
}
if (!move_uploaded_file($file["tmp_name"], $destination)) {
$arr = array('code' => 14, 'msg' => '移动文件出错', 'time' => $time);
echo json_encode($arr);
exit;
}
// 获取图片信息
$image_size = getimagesize($destination);
$width = $image_size[0];
$height = $image_size[1];
$type = $image_size[2];
// 打开原始图片
switch ($type) {
case 1:
$source = imagecreatefromgif($destination);
break;
case 2:
$source = imagecreatefromjpeg($destination);
break;
case 3:
$source = imagecreatefrompng($destination);
break;
default:
$arr = array('code' => 15, 'msg' => '不支持的文件类型', 'time' => $time);
echo json_encode($arr);
exit;
}
// 创建指定尺寸图片
$target = imagecreatetruecolor($targetWidth, $targetHeight);
imagecopyresampled($target, $source, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height);
imagejpeg($target, $destination, 90); // 保存为 JPEG 格式
imagedestroy($target);
// 生成缩略图
$thumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $width, $height);
$thumbPath = $destination_folder . "thumb/" . basename($destination);
if (!file_exists($destination_folder . "thumb/")) {
mkdir($destination_folder . "thumb/", 0777, true);
}
imagejpeg($thumb, $thumbPath, 80);
imagedestroy($source);
imagedestroy($thumb);
// 返回 JSON 数据
$fname = basename($destination);
$arr = array(
'code' => 1,
'msg' => $info . '上传成功',
'time' => $time,
'data' => array(
'src' => $imgurl .$destination_folder. $fname,
'thumbsrc' => $imgurl .$destination_folder. "thumb/" . $fname,
'name' => $fname,
'width' => $targetWidth,
'height' => $targetHeight,
'thumb_width' => $thumbWidth,
'thumb_height' => $thumbHeight
),
);
echo json_encode($arr);
exit;
}
|
评分
-
查看全部评分
|