jquery+php+ajax显示上传进度的多图片上传并生成缩略图代码_php技巧
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了jquery+php+ajax显示上传进度的多图片上传并生成缩略图代码_php技巧,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3559字,纯文字阅读大概需要6分钟。
内容图文
本例用到其他2个php class.upload.php和 functions.php还有css和js以及img文件完整实例代码点击此处本站下载。
效果图如下:
实现代码如下:
JavaScript代码如下:
代码如下:
javascript代码如下:
代码如下:
上面2个js都放在index.php里面
XML/HTML代码如下:
代码如下:
Name
Size
Status
Select files to upload
Upload
upload.php页面代码如下:
代码如下:<?php
/*
@@ Including the functions.php for using the necessary functions.
*/
include('functions.php');
/*
@@ This is the file upload class which does all the uploading work.
*/
include('class.upload.php');
if(isset($_FILES["file"])) {
/*
@@ Generating unique name for the photo.
*/
$time = time();
$rand_1 = rand(999, 999999);
$rand_2 = rand(999999, 999999999);
$rand_3 = rand();
$unique_value = $time.'_'.$rand_1.'_'.$rand_2.'_'.$rand_3;
/*
@@ Folder creation for each and every day. This ensures performance even with millions of images.
*/
$folder = date('zY');
if(substr($folder, 0) == 0) {
$folder = '367'.date('Y');
}
/*
@@ This folder is for the source image files.
*/
$pfolder = '../upload/source/';
if(!is_dir($pfolder)) {
mkdir($pfolder, 0755);
}
/*
@@ This folder is for the image files with 120x120 dimensions.
*/
$tfolder = '../upload/small/';
if(!is_dir($tfolder)) {
mkdir($tfolder, 0755);
}
/*
@@ Assigning the upload file to the upload class for all the processing.
*/
$handle = new Upload($_FILES["file"]);
if($handle->uploaded) {
$extension = $handle->file_src_name_ext;
$mime = $handle->file_src_mime;
if(($mime == 'image/gif') || ($mime == 'image/jpg') || ($mime == 'image/png') || ($mime == 'image/bmp') || ($mime == 'image/pjpeg') | ($mime == 'image/jpeg')) {
/*
@@ Check if the uploaded filetype is an image or not.
*/
if(($extension == 'gif') || ($extension == 'jpg') || ($extension == 'jpeg') || ($extension == 'png') || ($extension == 'bmp') || ($extension == 'pjpeg')) {
if($handle->image_src_x > 500) {
/*
@@ Check if the filesize is smaller than 10 MB. 10 MB = 10485760 bytes.
*/
if($handle->file_src_size < 10485760) {
/*
@@ Getting the actual file name (with and without extension) and sanitizing it for inserting in the database.
*/
$real_name = clean_input($handle->file_src_name);
$body_name = clean_input($handle->file_src_name_body);
$handle->file_new_name_body = $unique_value.'_'.$body_name;
$handle->Process($pfolder);
$handle->image_resize = true;
$handle->image_ratio_crop = 'T';
$handle->image_y = 120;
$handle->image_x = 120;
$handle->file_new_name_body = $unique_value.'_'.$body_name;
$handle->Process($tfolder);
if($handle->processed) {
$actual_name = $handle->file_dst_name;
$size = ceil($handle->file_src_size / 1024);
## Sending photo details back to the uploader.
$date = date("c", $time);
## Reducing the length of real name if it exceeds 50 characters.
if(strlen($real_name) > 50) {
$real_name = substr($real_name, 0, 50).'..';
}
echo 'success,'.$real_name.','.$date.','.$folder.','.$actual_name;
} else {
echo 'error,Upload Error
There was an error uploading the photo.';
}
} else {
echo 'error,Upload Error
The photo is bigger than the allowed upload size of 10MB.';
}
} else {
echo 'error,Upload Error
You are trying to upload a photo with smaller dimensions.';
}
} else {
echo 'error,Upload Error
Only photo uploads are allowed.';
}
} else {
echo 'error,Upload Error
Only photo uploads are allowed.';
}
} else {
echo 'error,Upload Error
An upload error occured.';
}
/*
@@ Return the json response to the script.
*/
$handle->Clean();
} else {
echo 'error,Upload Error
An upload error occured.';
}希望本文所述对大家的PHP+jQuery程序设计有所帮助。
内容总结
以上是互联网集市为您收集整理的jquery+php+ajax显示上传进度的多图片上传并生成缩略图代码_php技巧全部内容,希望文章能够帮你解决jquery+php+ajax显示上传进度的多图片上传并生成缩略图代码_php技巧所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。