Php file Upload class and explanation (12 ). The upload_tmp_dir parameter in the php Tutorial configuration is compared. if the file is under this directory, move_uploaded_file will be moved. In addition, this comparison is the upload_tmp_dir parameter in the case-sensitive php Tutorial configuration. if the file is under this directory, move_uploaded_file will be moved. And the comparison is case sensitive, and/is different under windows. When parsing the php configuration file, a realpath function is called, that is, before move_uploaded_file,
For $ file ['tmp _ name'] = realpath ($ file ['tmp _ name']); realpath.
In another case, you should note that if move_uploaded_file is configured as an inaccessible path, no matter how you handle it, move_uploaded_file will not be able to successfully move the file.
When uploading a file, you can use the move_uploaded_file function to move the file, but copy or rename is acceptable.
I have been confused. In this document, the description is vague, that is, the move_uploaded_file function, which adds a step-by-step check to check whether the file has been uploaded through http post,
Next I found a file Upload class on the Internet.
** 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)
{
$ This-> base_directory = $ directory; // Generate the root directory of the file store;
}
/** Initialize the file storage subdirectory **/
Function set_flash_directory ()
{
$ This-> flash_directory = $ this-> base_directory. "/". $ this-> date; // Generate a file storage subdirectory;
}
/** Handle errors **/
Function showerror ($ errstr = "unknown error! "){
Echo"