Php files are uploaded to the server. Uploading files using PHP
But at the beginning I would like to say a few words about how files are downloaded.
For this we need an html form with an input field like . In addition, to transfer files to the server, you must set the form type to multipart. To do this, as a parameter enctype value is indicated multipart/form-data.
After we place a form with a field on the html page A field will appear in the browser window allowing you to select a file on your local computer.
After the user selects required file and click the “Load” button, the form will submit php data script to the server specified in action forms. If the form's action is empty, then the data will be transferred to the same file on which the form is located. All information about the downloaded file is placed in an array $_FILES. All we have to do is extract this information and move the file to the location we need.
Before you start writing the processing script multipart forms, you need to edit the configuration file php.ini to allow files to be uploaded to the server.
Configuration PHP file php.ini has three parameters related to uploading files to the server:
- file_uploads = On - allows files to be uploaded to the server by HTTP protocol;
- upoad_tmp_dir = /tmp - sets the directory for temporary storage of downloaded files;
- upload_max_filesize = 2M - sets the maximum size of uploaded files.
So create new file with name upload.php and copy the following code into it.