PHP MySQL Upload File – image and PDF
To upload a file (image or PDF etc), we need to make one PHP file and folder for storing the images.
Code of upload.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?php $conn=mysqli_connect("localhost","root",""); mysqli_select_db($conn,"uploadfile"); if(isset($_REQUEST["submit"])) { $file=$_FILES["file"]["name"]; $tmp_name=$_FILES["file"]["tmp_name"]; $path="images/".$file; $file1=explode(".",$file); $ext=$file1[1]; $allowed=array("jpg","png","gif","pdf","wmv","pdf","zip"); if(in_array($ext,$allowed)) { move_uploaded_file($tmp_name,$path); mysqli_query($conn,"insert into store(file)values('$file')"); } } ?> <form enctype="multipart/form-data" method="post"> File Upload:<input type="file" name="file"> <input type="submit" name="submit" value="upload"> </form> |
Database View for PHP MySQL Upload File

Here, “uploadfile” is the database. “store” is the table name. Similarly, file is the attribute of the table store.