Have you ever wondered how websites build their system of file uploading in PHP? Here we will come to know about the file uploading process. A question which you can come up with – ‘Are we able to upload any kind of file with this system?’. The answer is yes, we can upload files with different types of extensions.
Let’s make an HTML form for uploading the file to the server.
Now, time to write a php script which is able to handle the file uploading system.
In the above script, once we submit the form, later we can access the information via a PHP superglobal associative array $_FILES. Apart form using the $_FILES array, many in-built functions are playing a major role. After we are done with uploading a file, in the script we will check the request method of the server, if it is POST then it will proceed otherwise the system will throw an error. Later on, we have accessed the $_FILES array to get the file name, file size, and type of the file. Once we got those pieces of information, then we validate the size and type of the file. In the end, we search in the folder, where the file is to be uploaded, for checking if the file already exists or not. If not, we have used move_uploaded_file() to move the file from temporary location to the desired directory on the server and we are done.
- File uploading in Node.js
- File uploading in React.js
- How to get file input by selected file name without path using jQuery ?
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | Basics of File Handling
- How to get file name from a path in PHP?
- PHP | $_FILES Array (HTTP File Upload variables)
- PHP | fopen( ) (Function open file or URL)
- How to log errors and warnings into a file in php?
- How to move a file into a different folder on the server using PHP?
- How to know which php.ini file is used ?
- How to change the maximum upload file size in PHP ?
- Download file from URL using PHP
- How to convert XML file into array in PHP?
- Convert multidimensional array to XML file in PHP
- How to delete a file using PHP ?
- How to copy a file from one directory to another using PHP ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.