Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

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.

Fazal Rehman Shamil Click Here to Know More
Instructor, Researcher, Blogger, SEO Expert, Poet and Publisher of International Journal Of Software, Technology & Science ISSN : 2616 - 5325
Dear Professors and Resarchers!You are welome to Cite these tutorials in your research or slides etc. Please don't forget to mention the reference of website. Copy Paste of text is strcitly forbidden. Images can be reuse because images are protected with watermark.