|
<? Php
/*
* 1: Upload successful
*-1: The file size exceeds the specified size.
*-2: The file type does not match
*-3: An error occurred while moving the file.
*/
If (is_uploaded_file ($ _ FILES ['upfile'] ['tmp _ name']) {
$ Photo_types = array ('image/jpg ', 'image/jpeg', 'image/png ', 'image/pjpeg', 'image/gif ', 'image/bmp ', 'image/x-png'); // defines the upload format
$ Max_size = 700000; // maximum size of the uploaded photo. The default value is 700 KB.
$ Photo_folder = "upload /". date ("Y "). "/". date ("m "). "/". date ("d "). "/"; // upload the photo path
//////////////////////////////////////// /// // Start processing the upload
If (! File_exists ($ photo_folder) // check whether the photo directory exists
{
Mkdir ($ photo_folder, 0777, true); // mkdir ("temp/sub, 0777, true );
}
$ Upfile = $ _ FILES ['upfile'];
$ Name = $ upfile ['name'];
$ Type = $ upfile ['type'];
$ Size = $ upfile ['SIZE'];
$ Tmp_name = $ upfile ['tmp _ name'];
$ File = $ _ FILES ["upfile"];
$ Photo_name = $ file ["tmp_name"];
// Echo $ photo_name;
$ Photo_size = getimagesize ($ photo_name );
If ($ max_size <$ file ["size"]) // check the file size
Echo "-1"; // echo "<script> alert ('Sorry, the file exceeds the specified size! '); History. go (-1); </script> ";
If (! In_array ($ file ["type"], $ photo_types) // check the file type
Echo "-2"; // echo "<script> alert ('Sorry, the file type does not match! '); History. go (-1); </script> ";
If (! File_exists ($ photo_folder) // photo directory
Mkdir ($ photo_folder );
$ Pinfo = pathinfo ($ file ["name"]);
$ Photo_type = $ pinfo ['extension']; // Upload File extension
$ Photo_server_folder = $ photo_folder.time (). ".". $ photo_type; // use the current time and a 7-bit random number as the file name. Here is the complete upload path.
If (! Move_uploaded_file ($ photo_name, $ photo_server_folder ))
{
Echo "-3"; // echo "An error occurred while moving the file ";
Exit;
}
$ Pinfo = pathinfo ($ photo_server_folder );
$ Fname = $ pinfo ['basename'];
Echo "1"; // echo "uploaded successfully:". $ photo_server_folder. "<br/> ";
}
?>
|