-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.php
61 lines (61 loc) · 1.88 KB
/
image.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<!-- java script usage-->
<script type="text/javascript">
function preview(event)
{
var reader= new FileReader();<!--var is used to declare variable/object in js-->
reader.onload=function()
{
var output= document.getElementById('output_image');
output.src=reader.result;
}
reader.readAsDataURL(event.target.files[0]);
}
</script>
</head>
<?php
include "conn.php";
$filerr="";
if(isset($_POST['submit']))
{
$id=$_POST['id'];
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
$file=file_get_contents($_FILES['file']['tmp_name']);
$img=base64_encode($file); // to conver the longblob datatype into strings and decimal using base64
$filetype=$_FILES['file']['type'];// to get the mime code of file
$img="data:$filetype;base64,$img";// furter explanation reqd
$cmd="update profile set photo='$img' where id='$id'";
if(mysqli_query($con,$cmd))
{
echo "image inserted successfully";
}
else
{
echo "error in insertion - $cmd";
}
}
else
{
$filerr= "please choose an image";
}
}
?>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];
?>" method="post" enctype="multipart/form-data">
<table>
<tr><th colspan="3">Please choose an image : </th></tr>
<tr><td>enter id</td><td colspan="2"><input type="text" name="id" /></td></tr>
<tr>
<td>Upload Image</td><td><input type="file" name="file" onchange="preview(event)" /></td><td width="100px" height="100px"><img id="output_image" width="100%" /></td><td><span style="color:#FF0000"><?php echo $filerr; ?></span></td>
</tr>
<tr><td colspan="2"><input type="reset"name="reset" value="cancel"/></td><td><input type="submit" name="submit" value="submit"/></td><td></td></tr>
</table>
</form>
</body>
</html>