A simple PHP file upload class. I found an image processing class when sorting out PHP classes. There are already many classes for PHP to process images, including those that process images separately, some that add watermarks, and some that generate images. In short In PHP, processing images is already very simple. Even in some small applications, the image uploading process can be realized by directly applying PHP's process orientation. Of course, in order to standardize the program, we still need to use PHP's object orientation.
The following PHP file upload class is mainly used to upload files, including pictures, videos, and word documents. In fact, it is recommended to use it to process pictures. The main reason for recommendation is that this class is very standardized and basically all The upload parameters can be defined in the class without modification in php.ini
The code is as follows | Copy code |
class files{ //File saving directory path $save_path = realpath($save_path) . '/'; //When files are uploaded $dbsave = ""; //The path stored in the database if ($dir_name !== '') { $y = date("Y"); $save_path .= $y . "/"; $save_path .= $m . "/"; $save_path .= $d . "/"; //New file name if (move_uploaded_file($tmp_name, $file_path) === false) { |
By using PHP's global array $_FILES, you can upload files from the client computer to a remote server.
The first parameter is the input name of the form, and the second subscript can be "name", "type", "size", "tmp_name" or "error". Like this:
•$_FILES["file"]["name"] - the name of the uploaded file
•$_FILES["file"]["type"] - The type of file being uploaded
•$_FILES["file"]["size"] - The size of the uploaded file, in bytes
•$_FILES["file"]["tmp_name"] - The name of the temporary copy of the file stored on the server
•$_FILES["file"]["error"] - Error code caused by file upload
This is a very simple way to upload files. For security reasons, you should add restrictions on who has permission to upload files.