php+ajax實(shí)現(xiàn)帶進(jìn)度條的上傳圖片功能【附demo源碼下載】
本文實(shí)例講述了php+ajax實(shí)現(xiàn)帶進(jìn)度條的上傳圖片功能。分享給大家供大家參考,具體如下:
運(yù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?'); }
完整實(shí)例代碼點(diǎn)擊此處本站下載。
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php文件操作總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語(yǔ)法入門(mén)教程》、《php操作office文檔技巧總結(jié)(包括word,excel,access,ppt)》、《php日期與時(shí)間用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
- PHP中使用Session配合Javascript實(shí)現(xiàn)文件上傳進(jìn)度條功能
- PHP 文件上傳進(jìn)度條的兩種實(shí)現(xiàn)方法的代碼
- PHP+Ajax異步帶進(jìn)度條上傳文件實(shí)例
- php上傳文件并顯示上傳進(jìn)度的方法
- PHP+FLASH實(shí)現(xiàn)上傳文件進(jìn)度條相關(guān)文件 下載
- jquery+php+ajax顯示上傳進(jìn)度的多圖片上傳并生成縮略圖代碼
- PHP + plupload.js實(shí)現(xiàn)多圖上傳并顯示進(jìn)度條加刪除實(shí)例代碼
- PHP+Ajax實(shí)現(xiàn)上傳文件進(jìn)度條動(dòng)態(tài)顯示進(jìn)度功能
- php ajax實(shí)現(xiàn)文件上傳進(jìn)度條
- PHP利用APC模塊實(shí)現(xiàn)文件上傳進(jìn)度條的方法
- PHP+apc+ajax實(shí)現(xiàn)的ajax_upload上傳進(jìn)度條代碼
- PHP使用Session實(shí)現(xiàn)上傳進(jìn)度功能詳解
相關(guān)文章
php 調(diào)用ffmpeg獲取視頻信息的簡(jiǎn)單實(shí)現(xiàn)
下面小編就為大家?guī)?lái)一篇php 調(diào)用ffmpeg獲取視頻信息的簡(jiǎn)單實(shí)現(xiàn)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04php讀取torrent種子文件內(nèi)容的方法(測(cè)試可用)
這篇文章主要介紹了php讀取torrent種子文件內(nèi)容的方法,可實(shí)現(xiàn)讀取并顯示torrent種子文件內(nèi)容的功能,簡(jiǎn)單實(shí)用,需要的朋友可以參考下2016-05-05利用PHP實(shí)現(xiàn)開(kāi)心消消樂(lè)的算法示例
開(kāi)心消消樂(lè)應(yīng)該對(duì)大家來(lái)說(shuō)都不陌生吧,下面這篇文章主要給大家介紹了關(guān)于如何利用PHP實(shí)現(xiàn)開(kāi)心消消樂(lè)算法的相關(guān)資料,文中將需求和示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-10-10php基于閉包實(shí)現(xiàn)函數(shù)的自調(diào)用(遞歸)實(shí)例分析
這篇文章主要介紹了php基于閉包實(shí)現(xiàn)函數(shù)的自調(diào)用,結(jié)合實(shí)例形式分析了php閉包實(shí)現(xiàn)遞歸的操作方法,需要的朋友可以參考下2016-11-11