Welcome folks I am back with another blog post. In this post we will be implementing How to perform File Upload Operation with PHP 7 from scratch. File Upload is one of the very important tasks in website development. Every website which has some functionality has file upload. Today in this post we will be looking at File Upload operation in PHP Programming language This process is illustrated in the next steps in a detailed fashion.

Before moving on to develop the application make sure you turn on the php File Upload directive present in the php.ini file of your web server. If you are using Xammp or any web server there is a configuration file present and in that there is a directive file_uploads. Make sure it is set to On.

Create a brand new index.html file. This will include the interface of the application. It will include the file upload button from which the users can upload the files to the server. Just copy paste the code given below..

After that write the server side code in the file which is mentioned in the form attribute i.e. upload.php. This file will contain the logic whenever the file is selected by the user and upload button is pressed then what server side code should run on the server. This file will contain that. Just copy paste the code written below and also read the explanation for each section of code.

In this section of the PHP script we are processing that whether the submitted file is an image or not. There is some bullet points to be noticed in the script which are as follows:

  • $imageFileType holds the file extension of the file (jpg, png etc)
  • $target_file specifies the full path of the file to be uploaded
  • $target_dir = “uploads/” – it specifies the directory where the file is going to be placed after it has been successfully uploaded.

 Notice , you need to create the uploads directory first before running the application.

Check if File Already Exists

limit file size

limit file type

complete file upload php script

Congratulations we are done Uploading files to Web Server using PHP 7 from scratch. Thanks for reading this post and if you like reading this and wants to read more of this please subscribe the blog below to get all the notications.

A programmer scientist by the mind and a passionate blogger by heart ❤️. Fountainhead of Coding Shiksha Life motto: Live while you can! Teach & inspire while you could & Smile while you have the teeth.

Gautam Sharma

Founder , Coding Shiksha

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *