PHP Upload a small case, based on the time: Month Day minutes Create a directory and randomly generate file names

Source: Internet
Author: User
<?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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.