您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php+ajax实现带进度条的上传图片功能实例详解

2025/8/3 6:25:58发布23次查看
这篇文章主要介绍了php+ajax实现带进度条的上传图片功能,涉及php文件传输及ajax无刷新提交的相关操作技巧,并附带demo源码供读者下载参考,需要的朋友可以参考下
运行效果图如下:
代码如下:
<?php if(isset($_files["fileinput"]) && $_files["fileinput"]["error"]== upload_err_ok) { ############ edit settings ############## $uploaddirectory = 'f:/websites/file_upload/uploads/'; //specify upload directory ends with / (slash) ########################################## /* note : you will run into errors or blank page if "memory_limit" or "upload_max_filesize" is set to low in "php.ini". open "php.ini" file, and search for "memory_limit" or "upload_max_filesize" limit and set them adequately, also check "post_max_size". */ //check if this is an ajax request if (!isset($_server['http_x_requested_with'])){ die(); } //is file size is less than allowed size. if ($_files["fileinput"]["size"] > 5242880) { die("file size is too big!"); } //allowed file type server side check switch(strtolower($_files['fileinput']['type'])) { //allowed file types case 'image/png': case 'image/gif': case 'image/jpeg': case 'image/pjpeg': case 'text/plain': case 'text/html': //html file case 'application/x-zip-compressed': case 'application/pdf': case 'application/msword': case 'application/vnd.ms-excel': case 'video/mp4': break; default: die('unsupported file!'); //output error } $file_name = strtolower($_files['fileinput']['name']); $file_ext = substr($file_name, strrpos($file_name, '.')); //get file extention $random_number = rand(0, 9999999999); //random number to be added to name. $newfilename = $random_number.$file_ext; //new file name if(move_uploaded_file($_files['fileinput']['tmp_name'], $uploaddirectory.$newfilename )) { die('success! file uploaded.'); }else{ die('error uploading file!'); } } else { die('something wrong with upload! is "upload_max_filesize" set correctly?'); }
总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。
相关推荐:
php实现的自定义数组排序函数与排序类
php实现批量获取网页中所有固定种子链接的方法
php实现二维数组按某列进行排序的方法_php技巧
以上就是php+ajax实现带进度条的上传图片功能实例详解的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product