Connect with us

WEB SOLUTIONS DONE

how to save uploaded image in database with php

html

how to save uploaded image in database with php

 

 

 

 

 

 

 

 

 how to save uploaded image in database with php

How to save uploaded image in database with php

image.html
source code is
<form method=”post” action=”upload.php” enctype=”multipart/form-data”>

<label>Choose File to Upload:</label><br />

<input type=”hidden” name=”id” />

<input type=”file” name=”uploadimage” /><br />

<input type=”submit” value=”upload” />

</form>

 

Next 

save-image.php

<?php
$target_Folder = “upload/”;

$uid = $_POST[‘id’];

$target_Path = $target_Folder.basename( $_FILES[‘uploadimage’][‘name’] );

$savepath = $target_Path.basename( $_FILES[‘uploadimage’][‘name’] );

$file_name = $_FILES[‘uploadimage’][‘name’];

if(file_exists(‘upload/’.$file_name))
{
echo “there exists that file aleady !”;
}
else
{
con=mysqli_connect(“server”,”username”,”password”,”database”);
if(mysqli_connect_errno())
{
echo “Failed to connect to database” . mysqli_connect_errno();
}

$sql = “INSERT INTO image (id,image, image_name)
VALUES (”,’$target_Folder$file_name’,’$file_name’) “;

if (!mysqli_query($con,$sql))
{
die(‘Error: ‘ . mysqli_error($con));
}
echo “1 record added successfully in the database”;
echo ‘<br />’;
mysqli_close($con);

//now the question is where to save uploaded image , we can save it in uploads folder//

move_uploaded_file( $_FILES[‘uploadimage’][‘tmp_name’], $target_Path );

echo “File Uploaded <br />”;
echo ‘File Successfully Uploaded to:&nbsp;’ . $target_Path;
echo ‘<br />’;
echo ‘File Name:&nbsp;’ . $_FILES[‘uploadimage’][‘name’];
echo'<br />’;
echo ‘File Type:&nbsp;’ . $_FILES[‘uploadimage’][‘type’];
echo'<br />’;
echo ‘File Size:&nbsp;’ . $_FILES[‘uploadimage’][‘size’];

}
?>

Continue Reading
You may also like...

More in html

Advertisement




To Top