How To Upload File To Server Using PHP & Save The Path In MySQL

When it comes to uploading file, the best way to do it, would be to upload the file to a file server and save the path of the file in the database. In this case, I have used PHP to upload the file to a directory and save the path of the file in the MySQL database.

Basically, you will need a simple HTML form and a PHP code to upload the file. So, here’s the HTML form.

And here’s the PHP code. Do note I have also added the logic to check whether the file is already there in the destination folder before the upload takes place.

So, that’s it for this tutorial. Stay tuned for more.

Author: Lahaul Seth

A programmer and a web developer, he is the founder of Lion Blogger. His main hobbies are web design & development and providing freelance writing services to clients.He works full time as a Senior Systems Engineer at Infosys Ltd.

Share This Post On
  • Bhagirath Sheela

    Thanks Man Great Code.Great Help

  • Wilkens Lavarin

    Great Content! Love the Work!!!

  • dickyibrohim

    That’s good Code and clear comment. Thankyou for your simple code but give newbie to easy understanding about the subject.

  • Abdullah Haider

    I think I’ve worked it out from the code:

    The Database is called: fileupload

    table:filedetails

    Rows:
    filepath
    filename
    description

  • Abdullah Haider

    what are the details of the database? e.g. the name of the tables and rows in the database?

Pin It on Pinterest

Share This
badge