Index.htm formenctype = multipart/form-dataaction = upload. phpmethod = postinputtype = hiddenname = MAX_FILE_SIZEvalue = 2000000 inputname = userfiletype = fileinput
Index.htm
Upload. php
$ F = $ _ FILES ['Jeff _ img_upload '];
// Check whether a file is uploaded
If ($ f ['error'] = 4 ){
Echo ("script" alert ('select the file you want to upload. thank you! 'Your region location.href}'index.htm'; script ");
}
Else {
// Error determination
If ($ f ['error']) {
Echo "failed. the file is too large! The error code is ". $ f ['error'];
Exit;
}
// Type determination
If (substr ($ f ['type'], 0, 5) = 'image '){
Switch ($ f ['type']) {
Case 'image/jpeg ':
Case 'image/jpg ':
Case 'image/pjpeg ':
$ Ext = '.jpg ';
Break;
Case 'image/GIF ':
$ Ext = '.gif ';
Break;
Case 'image/png ':
Case 'image/x-png ':
$ Ext = '.png ';
Break;
Default:
Header ('content-type: text/html; charset = UTF-8 ');
Echo ("script" alert ('didn't you upload an image? 'Your region location.href}'index.htm'; </script> ");
Die ('redirecting ...');
Break;
}
} Else {
Header ('content-type: text/html; charset = UTF-8 ');
Echo ("script" alert ('didn't you upload an image? 'Your region location.href}'index.htm'; script ");
Die ('redirecting ...');
}
// Generate a random number
$ Randomnum = NULL;
For ($ j = 0; $ j <= 5; $ j ++) // The length of a random number. In this example, the length of a random number is 6.
{
Srand (double) microtime () * 1000000 );
$ Randomnumber = rand (! $ J? 1:); // generates a random number, which is not the first number with 0. in some special cases, 0 is omitted by the system.
$ Randomnum. = $ randomnumber;
}
$ Dest_dir = '/var/www/htdocs/upload'; // sets the upload Directory
// Generate the date directory. First, determine whether the date directory exists. if it does not exist, create it.
If (! File_exists (date ("Ymd "))){
Mkdir (date ("Ymd"), 0777 );}
$ Dest = $ dest_dir. '/'. date ("Ymd "). '/'. time (). '_'. $ randomnum. $ ext; // Set the file name to the timestamp and add a random number to avoid duplication.
$ R = move_uploaded_file ($ f ['tmp _ name'], $ dest );
Chmod ($ dest, 0777); // sets the attributes of the uploaded file
}
Echo "succeeded. the file address is:". $ dest;
?>