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

PHP简单的悬浮于页面右侧在线购物车源码

一款php购物车实现示例代码,核心功能:商品列表、加入购物车、清空购物车。
  PHP笔记
 107  

PHP上传图片文件到服务器和MYSQL数据库实现源码

一款基于php+mysql上传图片并输出展示的源代码,核心功能:选择本地图片上传保存到服务器指定文件夹,同时把图片路径和图片名称保存到数据表,此源码无后台管理系统。
  PHP笔记
 76  

PHP+Ajax实现的在线事件日历管理示例源码

一款响应式可在线管理的事件日历代码,核心功能:日历展示、添加活动、移除活动。
  PHP笔记
 81  

PHP简单的实现动态数据渲染统计图源码

一款mysql动态数据创建条形图实现的程序源码,使用了Ajax动态获取数据表数据,回调渲染柱状统计图。
  PHP笔记
 115  

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

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