资源描述:此源码基于PHP+AJAX上传图片二进制文件,ajax请求将调用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. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服