The example of this article describes the Php+ajax implementation with progress bar upload picture function. Share to everyone for your reference, specific as follows:
The Operation effect chart is as follows:
The code is as follows:
<?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'll run int
o 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 "p
Ost_max_size ".
* *//check If this is a 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 Ty
PES 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 is 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? ');
}
Full instance code click here to download the site.
More interested in PHP related content readers can view the site topics: "PHP file Operation Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "Basic PHP Grammar Introduction Tutorial", "PHP operation Office Document skills Summary (including Word, Excel,access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.