1. First of all you will have to create HTML form for uploading any file through PHP

2. Create a folder in which you want to store uploaded files

 

When we upload a file we need to save file data base as well as in a folder.
Now we are going to do this…

<?php
if(isset($_POST[‘submit’])){
$pic=$_FILES[‘image’][‘name’];

$ext =pathinfo($pic, PATHINFO_EXTENSION);
$str=(string)$ext;
strtolower($str);
$sql=move_uploaded_file($_FILES[‘image’][‘tmp_name’],”images/”.$pic); //upload a file in folder

if($sql){
echo “<script>alert(‘Deal Added Succeessfully’);
window.location=’index1.php?viewdeal=view’;
</script>”;

}
else {
echo “Image Is Out Of Range”;

}

mysql_query(“insert into deal(image)values(‘$pic’)”)or die(mysql_error()); //upload a file in database

}

?>

<form method=”post” action=”” enctype=”multipart/form-data”>
<input type=”file” name=”image” id=”file”/>
<input type=”submit” value=”SUBMIT” name=”submit”>
</form
Note : (enctype=”multipart/form-data”) Do not forget to embeded that code in form.