Skip to main content

Upload, Download and Delete File using PHP MySQL

Language


In this article, we are going to learn how to create Upload, Download and Delete File using PHP MySQL. This simple program, a user can learn how to code for uploading, downloading, and deleting files using PHP MySQL. This program can serve as your File Manager.

Features

  • Upload any file
  • Download your file
  • Delete your file

Sample Source Code

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.  
  12. move_uploaded_file($temp,"files/".$name);
  13.  
  14. $query=$conn->query("INSERT INTO upload (name,date) VALUES ('$name','$date')");
  15. if($query){
  16. header("location:index.php");
  17. }
  18. else{
  19. }
  20. }
  21. ?>

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

Submitted byhahaa (not verified)on Thu, 08/18/2016 - 22:43

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)' in E:\xampp\htdocs\uploaddelete\myfilemgr\index.php:15 Stack trace: #0 E:\xampp\htdocs\uploaddelete\myfilemgr\index.php(15): PDO->__construct('mysql:host=loca...', 'root', '155300') #1 {main} thrown in E:\xampp\htdocs\uploaddelete\myfilemgr\index.php on line 15

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

$servername = "localhost";
$username = "root";
$password = "155300";
$dbname = "myweb";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

Submitted byZhafran (not verified)on Fri, 10/06/2017 - 10:45

Hello Ganeshrkt I have use your system for my work, now how can I give you some credit? Is it you give me to use your work?

Submitted byatiqah (not verified)on Mon, 10/16/2017 - 12:23

i got blank page when i execute the php file. Even the tittle didn't show up on my browser.

Submitted bytiqa (not verified)on Thu, 11/23/2017 - 16:30

Fatal error: Uncaught Error: Call to undefined function mysql_query() in C:\xampp\htdocs\uploaddelete\myfilemgr\index.php:125 Stack trace: #0 {main} thrown in C:\xampp\htdocs\uploaddelete\myfilemgr\index.php on line 125

i got this error whenever i try to access the page

Submitted byjohnkananaman (not verified)on Fri, 05/18/2018 - 10:35

Fatal error: Uncaught Error: Call to undefined function mysql_query() in C:\xampp\htdocs\frmdsystem\index.php:125 Stack trace: #0 {main} thrown in C:\xampp\htdocs\frmdsystem\index.php on line 125

Submitted bynaive code (not verified)on Thu, 05/24/2018 - 11:54

thank you so much for the system

Submitted bySyah Na'im (not verified)on Wed, 10/03/2018 - 12:47

Thanks for coding.
But I am got blank page after upload the file. Even upload was done but no data record in SQL. Please FIX it!

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.