How to Uplode file in database with php & html full source code

CREATE A DATABASE IN XAMPP or WAMP or any Sarver
Step 1 --->   Database Name "profile".
Step2 ---> Create a folder in the folder where you Work. Folder Name - "images".
.................................................................Save this "file_upload.php"

<!DOCTYPE html>
<html>
<head>
<title>File upload</title>
</head>
<body>
<table>
  <form enctype="multipart/form-data" method="post" action="upload_process.php">
<tr><td>
<input type="file" name="pic">
</td></tr>
<tr><td>
<input type="submit" name="upload" value="upload">
</td></tr>
</form>
</table>
</body>
</html>

................................................................Than save this "upload_process.php"

 <?php
include('connect.php');
if(isset($_POST['upload'])){
$target="images/";
$file=$_FILES['pic']['name'];
$size=$_FILES['pic']['size'];
$type=$_FILES['pic']['type'];

$filename=$target.basename($file);

$sql="INSERT INTO profile VALUES('0','$filename','0')";
$qry=mysqli_query($con,$sql);
if($qry){
$upload=move_uploaded_file($_FILES['pic']['tmp_name'], $filename);
if($upload==1){
echo "Uploaded";
}else{
echo "FIle NOt Uploaded";
}
}else{
echo "Error".mysqli_error($con);
}
}


?>



Than run file_upload.php

THANK YOU

Comments