PHP MySQL Upload File – image and PDF

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.

PHP image PDF

Code of upload.php

<?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

PHP MySQL Upload File - image and PDF
Figure: PHP MySQL Upload File – image and PDF

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

PHP Uploading Multiple Files on a single page

Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.