<? PHP
/**
* Page function: File Upload class. If a file with the same name exists, replace it
* Author: Happy with the wind
* Creation Time: 2006-3-6
* Other Instructions:
* 1. In the form, <input name = "up" type = "file">, the name parameter must be "up"
* 2. Check whether the file has been uploaded before use: $ _ FILES ['up'] ['SIZE']! = 0? Option: no option;
*/
Class class_ftp
{
Public $ file_ream; // returns the extension.
Public $ err; // returns the upload information.
Public $ off = false; // process switch/whether the upload is successful or not
/*
Parameter settings: $ file_max maximum size of uploaded files (KB)
$ File_dir upload path
$ File_type: supported types, for example, $ file_type = array ("image/pjpeg", "image/GIF ","**","**","**");
$ File_name rename the name after uploading (excluding the extension)
*/
Function _ construct ($ file_max, $ file_dir, $ file_type, $ file_name)
{
$ File_size = $ file_max * 1024; // convert it to the default byte of the system.
$ Num = sizeof ($ file_type); // obtain the number of supported types
// Check the file type
For ($ I = 0; $ I <$ num; $ I ++)
{
If ($ file_type [$ I] === _ FILES ['up'] ['type'])
{
$ This-> off = true;
Break;
}
}
If ($ this-> off = false) $ this-> err = "this file format is not supported! ";
// Check the file size
If ($ this-> off)
{
If ($ file_size <$ _ FILES ['up'] ['SIZE'])
{
$ This-> off = false;
$ This-> err = "the file size cannot exceed". $ file_max. "K! ";
}
}
// Check the copy file to the specified directory
If ($ this-> off)
{
// Get the extension
Switch ($ _ FILES ['up'] ['type'])
{
Case "image/pjpeg": $ this-> file_ream = ". jpg"; break;
Case "image/GIF": $ this-> file_ream = ". GIF"; break;
Case "text/plain": $ this-> file_ream = ". txt"; break;
Case "application/MSWord": $ this-> file_ream = ". Doc"; break;
Case "application/X-Shockwave-flash": $ this-> file_ream = ". SWF"; break;
Case "application/octet-stream": $ this-> file_ream = ". fla"; break;
Case "application/octet-stream": $ this-> file_ream = ". rar"; break;
Case "application/X-zip-compressed": $ this-> file_ream = ". Zip"; break;
Case "application/octet-stream": $ this-> file_ream = ". PSD"; break;
}
// Copy and upload files
Move_uploaded_file ($ _ FILES ['up'] ['tmp _ name'], $ file_dir. $ file_name. $ this-> file_ream );
If ($ _ FILES ['up'] ['error'] = 0)
{
$ This-> err = "the file is uploaded successfully! ";
}
Else
{
$ This-> off = false;
$ This-> err = "File Upload Failed. Please try again! ";
}
}
}
} // Class end
?>