Upload download file php mysql

PHP-MySQL-File-upload

How to upload and download files PHP and MySQL

This code example demonstrates the process to implement the file upload functionality in web applications and the following functionality will be implemented.

  • HTML form to upload .zip, .pdf, .docx, .ppt, as well as image files.
  • Upload .zip, .pdf, .docx, .ppt, as well as image files to server using PHP.
  • Store file name in the database using PHP and MySQL.
  • Retrieve .zip, .pdf, .docx, .ppt, as well as image files from the database and display in the web page.

Submitted by Ganeshrkt on Tuesday, September 14, 2021 - 14:30.

Upload download file php mysql

In this article, I will be sharing with you a simple Web Application called File Manager Web App. This mini-project was developed using PHP and MySQL Database. The application is able to store/Upload, retrieve, download, and delete files. In this project source code, you will learn how to manage file uploads using PHP Language. I am sharing this source code because I think this will be useful for your future project and to enhance your programming capabilities.

The File Manage Web App has simple features that are all related to the uploaded file. All the uploaded files are listed/displayed in a table that has a filter, sorting, and pagination feature using the DataTable library. In here, the application user can simply upload the file by choosing the file that he/she desired to upload and by clicking the Submit button, the file will be uploaded into the server and will be enlisted on the table. The user can download the file by clicking the attachement/paper clip icon and delete the file by clicking the trashcan icon.

Features

  • Upload any file
  • List the Files in the Table
  • Download your File uploaded
  • Delete your File uploaded
  • Table Pagination
  • Table row filtering
  • Table column ordering/sorting

Here's the a sample source code that I used on this simple Web Application

This PHP source code contains INSERT Statement to save the data into the database.

  1. <?php

  2. $conn=new PDO('mysql:host=localhost; dbname=myweb', 'root', '') or die(mysql_error());

  3. if(isset($_POST['submit'])!=""){

  4. $name=$_FILES['photo']['name'];

  5. $size=$_FILES['photo']['size'];

  6. $type=$_FILES['photo']['type'];

  7. $temp=$_FILES['photo']['tmp_name'];

  8. $date = date('Y-m-d H:i:s');

  9. $caption1=$_POST['caption'];

  10. $link=$_POST['link'];

  11. $query=$conn->query("INSERT INTO upload (name,date) VALUES ('$name','$date')");

  12. if($query){

  13. header("location:index.php");

  14. }

  15. else{

  16. }

  17. }

  18. ?>

The File Manager Web Application's Source Code is free to download on this website. Feel free to download and modify it the way you wanted.

How to Run ??

Requirements

  • Download and Install any local web server such as XAMPP/WAMP.
  • Download the provided source code zip file. (download button is located below)

Installation/Setup

  1. Open your XAMPP/WAMP's Control Panel and start Apache and MySQL.
  2. Extract the downloaded source code zip file.
  3. If you are using XAMPP, copy the extracted source code folder and paste it into the XAMPP's "htdocs" directory. And If you are using WAMP, paste it into the "www" directory.
  4. Browse the PHPMyAdminin a browser. i.e. http://localhost/phpmyadmin
  5. Create a new database naming myweb.
  6. Import the provided SQLfile. The file is known as upload.sql located inside the SQL folder.
  7. Browse the Simple File Manager Web App in a browser. i.e. http://localhost/myfilemgr.

DEMO

That's it! You can now test the features and functionlities of this Simple File Manager Web App in PHP and MySQL Database. I hope this will help you with what you are looking for and for your future projects.

Happy Coding!!

  • 10223 views

How can I download uploaded file in php?

Declare a variable and store the directory name where the downloaded file will save. Use the basename() function to return the file basename if the file path is provided as a parameter. Save the file to the given location. Open the saved file location in write string mode.

How can show uploaded file in php?

PHP File Upload.
Configure The "php.ini" File. First, ensure that PHP is configured to allow file uploads. ... .
Check if File Already Exists. Now we can add some restrictions. ... .
Limit File Size. The file input field in our HTML form above is named "fileToUpload". ... .
Limit File Type. ... .
Complete Upload File PHP Script..

Can we store PDF files in MySQL?

A Binary Large Object ( BLOB ) is a MySQL data type that can store binary data such as images, multimedia, and PDF files.

How do I add a file to a MySQL database?

Add File Uploads CREATE TABLE uploads (id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY, description CHAR(50), data LONGBLOB, filename CHAR(50), filesize CHAR(50), filetype CHAR(50) ); The first thing you should notice is a field called id that is set to AUTO_INCREMENT.