<? Php
/**
* Bkjia.com-personal experience is very simple. Anyone who has a PHP base should be able to understand it ~~
* Apache2 + PHP5.0
* Version: 1.0
* At the same time, I would like to thank all the brothers of bkJia.
* --------------------------------- Example-
* Test. php @ process the Form file name
* <? Php
*
* Include ("upload. php"); # Add a class file
* $ F_upload = new upload_other; # create an object
* $ F_upload-> set_file_type ($ _ FILES [src] [type]); # obtain the file type
* $ F_upload-> set_file_name ($ _ FILES [src] [name]); # obtain the file name
* $ F_upload-> set_file_size ($ _ FILES [src] [size]); # obtain the file size
* $ F_upload-> set_upfile ($ _ FILES [src] [tmp_name]); # temporary file name stored on the server
* $ F_upload-> set_size (100); # sets the maximum number of uploaded KB.
* $ F_upload-> set_base_directory ("uploadImages"); # Name of the root directory of the file storage
* $ F_upload-> set_url ("up. php"); # The object to jump to after the file is uploaded successfully
* $ F_upload-> save (); # save an object
*
*?>
* ---------------------------------- End-
*
* I have not performed any file verification in the class. You can do this at the front end ~~
*
* -------------------------- Form-
* Upload.htm @ Form file name
*
* <Html>
* <Head>
* <Title> File Upload instance </title>
* </Head>
* <Body>
* <Form action = "test. php" method = "post" enctype = "multipart/form-data">
* <Table border = 0 cellPadding = 3 cellSpacing = 4 width = 30%>
* <Tr>
* <Td width = 10% nowrap> attachment source </td>
* <Td> <input name = "src" type = "file"/> </td>
* </Tr>
* <Tr>
* <Td colSpan = 2 align = center> <input type = "submit" value = "Upload"> </td>
* </Tr>
* </Table>
* </Form>
* </Body>
* </Html>
*
* ---------------------------- End-
*
* The preceding two files can be merged or not merged as needed ~~ If you have any questions, contact me ~~ Pai_^
*
**/
/** File Upload class **/
Class upload_file
{
/** Declaration **/
Var $ upfile_type, $ upfile_size, $ upfile_name, $ upfile;
Var $ d_alt, $ extention_list, $ tmp, $ arri;
Var $ datetime, $ date;
Var $ filestr, $ size, $ ext, $ check;
Var $ flash_directory, $ extention, $ file_path, $ base_directory;
Var $ url; // The jump path after the file is uploaded successfully;
Function upload_file ()
{
/** Constructor **/
$ This-> set_url ("index. php"); // jump path after successful initialization upload;
$ This-> set_extention (); // initialize the extension list;
$ This-> set_size (50); // initialize the size limit of kb for the uploaded file;
$ This-> set_date (); // you can specify the directory name;
$ This-> set_datetime (); // you can specify the file name prefix;
$ This-> set_base_directory ("attachmentFile"); // initialize the File Upload root directory name, which can be modified !;
}
/** File type **/
Function set_file_type ($ upfile_type)
{
$ This-> upfile_type = $ upfile_type; // obtain the file type;
}
/** Get the file name **/
Function set_file_name ($ upfile_name)
{
$ This-> upfile_name = $ upfile_name; // obtain the file name;
}
/** Get file **/
Function set_upfile ($ upfile)
{
$ This-> upfile = $ upfile; // obtain the temporary file name stored on the server;
}
/** Get the file size **/
Function set_file_size ($ upfile_size)
{
$ This-> upfile_size = $ upfile_size; // obtain the file size;
}
/** Set the jump path after the file is uploaded successfully **/
Function set_url ($ url)
{
$ This-> url = $ url; // sets the Redirect path after the file is uploaded successfully;
}
/** Get the file extension **/
Function get_extention ()
{
$ This-> extention = preg_replace (/. *. (. * [^.]. *) */iU, \ 1, $ this-> upfile_name); // obtain the file extension;
}
/** Set the file name **/
Function set_datetime ()
{
$ This-> datetime = date ("YmdHis"); // generate the file name by time;
}
/** Set the directory name **/
Function set_date ()
{
$ This-> date = date ("Y-m-d"); // generate a directory name by date;
}
/** Initialize the file type that can be uploaded **/
Function set_extention ()
{
$ This-> extention_list = "doc | xls | ppt | avi | txt | gif | jpg | jpeg | bmp | png"; // The default extended name that can be uploaded;
}
/** Set the maximum upload KB limit **/
Function set_size ($ size)
{
$ This-> size = $ size; // you can specify the maximum file size that can be uploaded;
}
/** Initialize the root directory of the file storage **/
Function set_base_directory ($ directory)
{
& N