Need a Website Or Web Application Or Any Help In Code , Contact Us: +91 9437911966 (Whatsapp), Note: Paid Service
Students Tutorial app relased. Download Now.

How to upload file In PHP

For upload file in MySQL first we have to create a table in data base.

Here we using 2 file for upload file:

<!DOCTYPE html>
<title>File Upload</title>
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<button type="submit" name="upload">upload</button>
include_once 'database.php';
 $file = rand(1000,100000)."-".$_FILES['file']['name'];
    $file_loc = $_FILES['file']['tmp_name'];
 $file_size = $_FILES['file']['size'];
 $file_type = $_FILES['file']['type'];
 /* new file size in KB */
 $new_size = $file_size/1024;  
 /* new file size in KB */
 /* make file name in lower case */
 $new_file_name = strtolower($file);
 /* make file name in lower case */
 $final_file=str_replace(' ','-',$new_file_name);
  $sql="INSERT INTO image(file,type,size) VALUES('$final_file','$file_type','$new_size')";
  echo "File sucessfully upload";
  echo "Error.Please try again";