How to File Upload in Database using PHP

How to File Upload in Database using PHP

In this article, How to File Upload in Database using PHP.

Follow below Steps:

HTML Code:

file.php

<html>
<head>
<title>File Upload</title>
<form method="post" enctype="multipart/form-data" action="upload.php">
<input class="tbl2" type="file" name="f"><span class="txt1">(Type : .jp/* /* eg, .jpg, .gif, .png)</span>
<input class="butt2 bt" type="submit" value="save" name="save">
</form>
</body>
</html>

PHP Code:

upload.php

<?php
include('db.php');
if(!empty($_REQUEST['save']))
	{
		
		
		$st2=1;
		$filename=$_FILES['f']['name'];
		$filepath=$_FILES['f']['tmp_name'];
		$ext=end(explode('.',$filename));
		$query="show table status like 'product'";
		
		
		$fullfilename=$id.".".$ext;
		
		
		{
			$query="insert into product(filename) values('$fullfilename')";
		}
?>

db.php

<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('database');
?>

How to Insert Data into Mysql Database using PHP

Read on Facebook

Leave A Reply