This article adds a simple php File Upload instance to favorites. This is really a super simple file upload function code. We use php $ files to obtain the type of the file to be uploaded, name and temporary name. Then, use move_uploaded_file to save the file to the specified directory on the server. This article adds a simple php File Upload instance to favorites. This is really a super simple file upload function code. We use php $ files to obtain the type of the file to be uploaded, name and temporary name. Then, use move_uploaded_file to save the file to the specified directory on the server.
Script ec (2); script
Html code
Process and upload php code
The Code is as follows: |
|
Function do_upload ($ upload_dir, $ upload_url) { $ Temp_name = $ _ files ['userfile'] ['tmp _ name']; $ File_name = $ _ files ['userfile'] ['name']; $ File_name = str_replace ("\", "", $ file_name ); $ File_name = str_replace ("'", "", $ file_name ); $ File_path = $ upload_dir. $ file_name; $ Thistime = explode ("-", date ("y-m-d-h-I-s ")); $ Thistime = mktime (); $ Filename = $ thistime. substr ($ file_name, strrpos ($ file_name ,".")); // Check the file name If ($ file_name = '') { Echo "the file name is invalid. "; Exit; } If (@ move_uploaded_file ($ _ files ['userfile'] ['tmp _ name'], $ upload_dir. $ filename )) { Echo "uploaded successfully. "; Echo" "; Exit; } Else { Echo "Upload Failed. "; Echo" "; Exit; } Echo "end "; } ?>
|
The Code is as follows: |
|
Call Method |
The Code is as follows: |
|
$ Upload_dir = 'down .111cn.net '; $ upload_url = 'www .111cn.net '; |
The Code is as follows: |
|
Do_upload ($ upload_dir, $ upload_url );
|