最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php+ajax實現(xiàn)帶進度條的上傳圖片功能【附demo源碼下載】

 更新時間:2016年09月14日 12:14:06   作者:懶人  
這篇文章主要介紹了php+ajax實現(xiàn)帶進度條的上傳圖片功能,涉及php文件傳輸及ajax無刷新提交的相關操作技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下

本文實例講述了php+ajax實現(xiàn)帶進度條的上傳圖片功能。分享給大家供大家參考,具體如下:

運行效果圖如下:

代碼如下:

<?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相關內(nèi)容感興趣的讀者可查看本站專題:《php文件操作總結》、《PHP運算與運算符用法總結》、《PHP網(wǎng)絡編程技巧總結》、《PHP基本語法入門教程》、《php操作office文檔技巧總結(包括word,excel,access,ppt)》、《php日期與時間用法總結》、《php面向對象程序設計入門教程》、《php字符串(string)用法總結》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設計有所幫助。

相關文章

最新評論

承德市| 仁化县| 新田县| 周宁县| 黄大仙区| 苏尼特左旗| 长治市| 孝昌县| 花莲市| 弥勒县| 连南| 开封县| 察雅县| 朝阳区| 新密市| 册亨县| 古田县| 托克托县| 望奎县| 虎林市| 大港区| 太原市| 陇南市| 达州市| 全南县| 赤峰市| 叶城县| 桂平市| 长丰县| 竹北市| 万源市| 陇西县| 望城县| 安图县| 商洛市| 衡南县| 安丘市| 额敏县| 鱼台县| 巩留县| 汾西县|