Introduction: This is a PHP Upload class (home) detailed page, introduced and PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 324387 'rolling = 'no'>
<? PHP
/**
* File up load class
* @ Version 1.0.0 (Thu Aug 18 01:32:39 CST 2005)
* @ Author sanshi
*/
Class upload
{
/**
*
* @ Author sanshi
* @ Version 1.0.0 Thu Aug 18 01:00:18 CST 2005
* @ Param string $ info file content
* @ Param string $ file name generated by filename
* @ Return Boolean return true if creation is successful
* @ Deprecated
* Create an HTML file
*/
Function createhtml ($ info, $ filename)
{
}
/**
*
* @ Author sanshi
* @ Version 1.0.0 Thu Aug 18 01:03:09 CST 2005
* @ Return void
* @ Deprecated
* Constructor
*/
Function download ()
{}
/**
*
* @ Author sanshi
* @ Version 1.0.0 Thu Aug 18 01:03:55 CST 2005
* @ Param string $ field name of filefield in the form
* @ Param string $ length limit
* @ Return Boolean success return true
* @ Deprecated
* Function implementation functions
*/
Function Init ($ filefield, $ length = '')
{
$ Files = $ _ FILES [$ filefield];
// Change the user name based on your actual situation.
$ Username = 'sanshi ';
$ Filename = $ files ['name'];
$ Filetype = $ files ['type'];
$ Filetemp = $ files ['tmp _ name'];
$ Filesize = empty ($ length )? ($ Files ['SIZE'] 10): $ length;
$ Fileerror = $ files ['error']; // This part may not exist in PhP4
// Change
// If ($ this-> _ istype ($ filename) | $ this-> _ isbig ($ length ))
If (! $ This-> _ istype ($ filename) | $ this-> _ isbig ($ length) | $ fileerror! = 0)
{
// Print_r ($ files );
Return false;
} Else {
$ Path = $ this-> _ createdir ($ username); // obtain the path
$ Createfilename = $ username. "_". Time (); // set the current file name
$ Createfiletype = $ this-> getfiletype ($ filename); // you can specify a file category.
Return @ move_uploaded_file ($ filetemp, $ path. $ createfilename. '.'. $ createfiletype )? True: false;
}
}
/**
*
* @ Author sanshi
* @ Version 1.0.0 Thu Aug 18 01:07:43 CST 2005
* @ Param int $ Length indicates the maximum size of the object to be uploaded.
* @ Return Boolean return true if the value is greater
* @ Deprecated
* Determine whether the specified size is exceeded.
*/
Function _ isbig ($ length)
{
$ Bigest = '';
Return $ big> $ bigest? True: false;
}
/**
*
* @ Author sanshi
* @ Version 1.0.0 Thu Aug 18 01:08:55 CST 2005
* @ Param string $ filename file name
* @ Return string $ filetype file suffix
* @ Deprecated
* Get the file suffix (only get the last Suffix of the file)
*/
Function getfiletype ($ filename)
{
Return end (explode ('.', $ filename ));
}
/**
*
* @ Author sanshi
* @ Version 1.0.0 Thu Aug 18 01:10:41 CST 2005
* @ Param string $ filename file name
* @ Param Boolean $ method whether to check multiple suffixes; default value: false
* @ Param int $ Postfix the default number of suffixes is 2
* @ Return Boolean returns true if a Boolean exists.
* @ Deprecated
* Check whether the file suffix is in the category array. Set the category array by yourself.
* If $ method is set to true, check the file with several suffixes.
*/
Function _ istype ($ filename, $ method = 'false', $ Postfix = 2)
{
// Set the category Array
$ Type = array ('jpeg ',
'Gif ',
'Bmp ',
'Exe ');
$ Filename = strtolower ($ filename );
$ Filetypearray = explode ('.', $ filename );
$ Filetype = end ($ filetypearray );
// Determine whether a file has multiple suffixes
If ($ method)
{
If (count ($ filetypearray)> (is_int ($ postfix )? $ Postfix: 2 ))
{
Return false;
}
}
Return in_array ($ filetype, $ type );
}
/**
*
* @ Author sanshi
* @ Version 1.0.0 Thu Aug 18 01:17:19 CST 2005
* @ Param string $ username
* @ Return string $ path
* @ Deprecated
* Create a directory in the format of year/month/day/user name/
* The permission is 755.
*/
Function _ createdir ($ username)
{
$ Root = '';
$ Pathsign = directory_separator;
$ Y = Date ('y'). $ pathsign;
$ M = Date ('M'). $ pathsign;
$ D = Date ('D'). $ pathsign;
$ Path = $ root. $ Y. $ M. $ D. $ username;
$ Dirarray = explode ($ pathsign, $ PATH );
$ Tempdir = '';
Foreach ($ dirarray as $ DIR)
{
$ Tempdir. = $ dir. $ pathsign;
$ Isfile = file_exists ($ tempdir );
Clearstatcache ();
If (! $ Isfile &&! Is_dir ($ tempdir ))
{
@ Mkdir ($ tempdir, 0755 );
}
}
Return $ path. $ pathsign;
}
/**
*
* @ Author sanshi
* @ Version 1.0.0 Thu Aug 18 01:19:32 CST 2005
* @ Param string $ dirname directory name
* @ Return Boolean the return value is true.
* @ Deprecated
* Determine whether the operation is in the upload directory
*/
Function _ isdel ($ dirname)
{
// Pay attention to uploaddir, which must correspond to the actual directory used
$ Uploaddir = '';
$ Uploaddir = preg_replace ('// \\//', '\/', $ uploaddir );
$ Format = "/^ {$ uploaddir }/";
Return preg_match ($ format, $ dirname );
}
/**
*
* @ Author sanshi
* @ Version 1.0.0 Thu Aug 18 01:25:58 CST 2005
* @ Param string $ filename file name
* @ Return Boolean returns true if the object is successfully deleted.
* @ Deprecated
* Delete an object
*/
Function delfile ($ filename)
{
$ Cur_dir = dirname (TRIM ($ filename ));
If ($ this-> _ isdel ($ cur_dir ))
{
Return @ unlink ($ filename )? True: false;
} Else {
Return false;
}
}
/**
*
* @ Author sanshi
* @ Version 1.0.0 Thu Aug 18 01:27:43 CST 2005
* @ Param string $ diename directory name
* @ Return Boolean return true If deletion is successful
* @ Deprecated
* Deleting files in the directory cannot be deleted.
*/
Function deldir ($ dirname)
{
If ($ this-> _ isdel ($ dirname) & is_dir ($ dirname ))
{
Return @ rmdir ($ dirname )? True: false;
} Else {
Return false;
}
}
}
?>
<? PHP
// Use
/*
Include 'upload. Class. php ';
$ Up = new upload ();
If ($ up-> Init ("file "))
{
Echo 'success ';
} Else {
Echo 'failure ';
}
*/
?>
More articles on "PHP Upload class (for your own use)"
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/324387.html pageno: 15.