侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

php+ajax实现带进度条的上传图片功能【附demo源码下载】

2023-02-22 星期三 / 0 评论 / 0 点赞 / 37 阅读 / 3596 字

本文实例讲述了php+ajax实现带进度条的上传图片功能。分享给大家供大家参考,具体如下:运行效果图如下:代码如下:<phpif(isset($_FILES["FileInput"]) && $_FILES["FileI

本文实例讲述了php+ajax实现带进度条的上传图片功能。分享给大家供大家参考,具体如下:

运行效果图如下:

代码如下:

.
<?phpif(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基本语法入门教程》、《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

希望本文所述对大家PHP程序设计有所帮助。

广告 广告

评论区