/
uploadPics.php
72 lines (71 loc) · 2.29 KB
/
uploadPics.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
62
63
64
65
66
67
68
69
70
71
72
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="main.css">
<link rel="icon" href="P.png">
<link rel="stylesheet" href="animate.css">
<title>Upload Image</title>
</head>
<body>
<div id="main">
<div align="center" id ="h11">
<h2>Choose a file to upload!</h2>
</div>
<div align="center" id="uplddiv1">
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input id="inputfile" name="userfile" type="file"/>
<br/>
<h4>Give a name for the image:</h4>
<input type="text" name="imageName">
<br/><br/>
<input type="submit" id="btn2" value="PUSH!!"/>
</form>
</div>
</div>
<?php
$msg=0;
session_start();
if(isset($_FILES['userfile'])){
try {
$msg= upload();
echo $msg;
}
catch(Exception $e) {
echo $e->getMessage();
echo 'Sorry, could not upload file';
}
}
function get_extension($file) {
$extension = end(explode(".", $file));
return $extension;
}
function upload() {
$msg =9;
$con = mysqli_connect('localhost','shibli','shibli');
mysqli_select_db ($con,'piclib');
$imaget = mysqli_real_escape_string($con,$_FILES["userfile"]["type"]);
$f = substr($imaget,0,5);
if($f=="image"){
if(is_uploaded_file($_FILES['userfile']['tmp_name'])){
header("location: http://localhost:63342/VideoLibraryApp/views/fun.php");
}
$imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name']));
$ext = get_extension($_FILES['userfile']['name']);
$query2= " Select max(imageID) from imgdata;";
$result2 = mysqli_query($con,$query2);
$row2 = mysqli_fetch_row($result2);
$r = $row2[0]+1;
$sql = "INSERT INTO imgdata values($r,'$ext','$_POST[imageName]','$_POST[user]','{$imgData}')";
mysqli_query($con,$sql) or die("Error in Query: " . mysqli_error($con));
header("location: http://localhost:63342/VideoLibraryApp/views/displayLogged.php");
}
else{
//$finfo = finfo_open(FILEINFO_MIME_TYPE);
//finfo_file($finfo, $_FILES['userfile']['tmp_name']);
header("location: http://localhost:63342/VideoLibraryApp/views/main.css");
}
return $msg;
}
?>
</body>
</html>