Upload one or more files-php? & Lt ;? Php ** author Coco * date 2011-1-20 *** $ field specifies the input field name in the form * $ type specifies the file type to be uploaded * $ dir specifies the file storage path, the relative path (beginning and ending with) * $ maxsize limits the size (in bytes) of the uploaded file. by default, one or more file uploads are not limited. -- php
?
0 & $ file [size]> $ maxsize) return "size"; if (! Is_dir ($ dir) mkdir ($ dir); list ($ second, $ unix) = explode ("", microtime (); $ name = $ unix. ($ second * 100000000 ). strstr ($ file [name], ". "); // rename the uploaded file by time, accurate to microsecond move_uploaded_file ($ file [tmp_name], $ dir. $ name); return $ name;}/** $ field specifies the input field name in the form ending with [], for example, image [] */function uploadfile_table ($ field, $ type, $ dir, $ maxsize = 0) {if ($ _ FILES [$ field]! = Null) {$ file = $ _ FILES [$ field]; $ count = count ($ file [name]); $ arr = array (); if (! Is_dir ($ dir) mkdir ($ dir); for ($ I = 0; $ I <$ count; $ I ++) {if ($ file [error] [$ I] = 1) {$ arr [$ I] = "error"; continue;} if ($ type! = Strstr ($ file [type] [$ I], "/", true) {$ arr [$ I] = "type"; continue ;} if ($ maxsize> 0 & $ file [size] [$ I]> $ maxsize) {$ arr [$ I] = "size"; continue ;} list ($ second, $ unix) = explode ("", microtime (); $ name = $ unix. ($ second * 100000000 ). strstr ($ file [name] [$ I], ". "); move_uploaded_file ($ file [tmp_name] [$ I], $ dir. $ name); $ arr [$ I] = $ name;} return $ arr ;}} echo""; // Print_r (uploadfile (" upimage "," image ", $ _ SERVER ['document _ root']. "/picture/", 5120); // upload a single file print_r (uploadfile_table ("upimage", "image", $ _ SERVER ['document _ root']. "/picture/"); // upload multiple file echo"
"?>
?
Upload multiple files
?
?