<?php/* receive files and sub-directory store, generate random file name 1. According to the timestamp, and according to a certain rule to create a directory 2. Gets the suffix name of the file name 3. Determine the size *///calculates and creates the directory function Mk_dir () {$dir = date (' MD /I ', Time ()), if (Is_dir ('./'. $dir)) {return $dir;} Else{mkdir ('./'. $dir, 0777,true); return $dir;}} Gets the file suffix function getext ($file) {$tmp = explode ('. ', $file); return end ($TMP);} Randomly generates the moved file name function Randname () {$str = ' abcdefghijkmnpqrstwxyz23456789 '; return substr (Str_shuffle ($STR), 0,6);} Judge the error code, =0 upload Success,! =0 upload failed if ($_files[' pic ' [' ERROR ']!=0) {echo "Upload failed"}//process upload process $pic = $_files[' pic '];//stitching file path $path = './'. Mk_dir (). ' /'. Randname (). '. '. Getext ($pic [' name ']);//Move if (Move_uploaded_file ($pic [' tmp_name '), $path) {echo ' upload succeeded ';} else{echo "Upload failed";}? >
PHP Upload a small case, based on the time: Month Day minutes Create a directory and randomly generate file names