PHP上传图片生成多张不同尺寸缩略图示例源码

所属分类: PHP源码-PHP笔记    2024-01-22 08:51:09

PHP上传图片生成多张不同尺寸缩略图示例源码 ie兼容6

PHP上传图片生成多张不同尺寸缩略图示例源码(共7个文件)

    • image_upload_submit.php
    • functions.php
    • index.php

使用方法

<?php
require_once('functions.php');

if(isset($_FILES['image_file_input']))
 {
	$output['status']=FALSE;
	set_time_limit(0);
	$allowedImageType = array("image/gif",   "image/jpeg",   "image/pjpeg",   "image/png",   "image/x-png"  );
	
	if ($_FILES['image_file_input']["error"] > 0) {
		$output['error']= "File Error";
	}
	elseif (!in_array($_FILES['image_file_input']["type"], $allowedImageType)) {
		$output['error']= "Invalid image format";
	}
	elseif (round($_FILES['image_file_input']["size"] / 1024) > 4096) {
		$output['error']= "Maximum file upload size is exceeded";
	} else {
	    $temp_path = $_FILES['image_file_input']['tmp_name'];
		$file = pathinfo($_FILES['image_file_input']['name']);
		$fileType = $file["extension"];
		$fileName = rand(222, 888) . time() . ".$fileType";
		
		$small_thumbnail_path = "uploads/small/";
		createFolder($small_thumbnail_path);
		$small_thumbnail = $small_thumbnail_path . $fileName;
		
		$medium_thumbnail_path = "uploads/medium/";
		createFolder($medium_thumbnail_path);
		$medium_thumbnail = $medium_thumbnail_path . $fileName;
		
		$large_thumbnail_path = "uploads/large/";
		createFolder($large_thumbnail_path);
		$large_thumbnail = $large_thumbnail_path . $fileName;
		
		$thumb1 = createThumbnail($temp_path, $small_thumbnail,$fileType, 150, 93);
		$thumb2 = createThumbnail($temp_path, $medium_thumbnail, $fileType, 300, 185);
		$thumb3 = createThumbnail($temp_path, $large_thumbnail,$fileType, 550, 340);
				
		if($thumb1 && $thumb2 && $thumb3) {
		    $output['status']=TRUE;
		    $output['small']= $small_thumbnail;
		    $output['medium']= $medium_thumbnail;
        		$output['large']= $large_thumbnail;
		}
	}
	echo json_encode($output);
}
?>	

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / PHP笔记

PHP多文件上传并在线生成ZIP压缩包示例源码

这是一款多文件上传压缩工具类源码,核心功能:可选择多个文件同时上传、同步在线生成ZIP压缩包文件。
  PHP笔记
 1857  0

PHP会话session在30秒钟后自动销毁实现代码

这是一款自定义会话变量过期时间代码,基于php核心函数session_destroy()来清除所有会话值,并且它是一个简单的无参数函数,返回布尔值true或false。
  PHP笔记
 2709  0

PHP在线贴纸便签记事本网站源码

一款简易的在线记事本系统源码,核心功能:贴纸列表、查看内容、编辑内容、删除内容。
  PHP笔记
 21220  0

PHP带AJAX搜索查询的分页代码源码

一款基于php+ajax实现动态分页源代码,AJAX获取MYSQL数据库中的数据,然后返回给前台页面,从而实现分页功能,带字段搜索查询功能。此源码不带后台管理系统。
  PHP笔记
 9706  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论