-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuploadpixfunc.php
49 lines (43 loc) · 1.83 KB
/
uploadpixfunc.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
<?php
session_start();
$DB_DSN = 'localhost';
$DB_USER = 'root';
$DB_PASSWORD = '';
$DB_NAME = 'matcha2';
//connect to the newly created database
try {
$conn = new PDO("mysql:host=$DB_DSN;dbname=$DB_NAME", $DB_USER, $DB_PASSWORD);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
$firstPic = 0;
if (count($_FILES) > 0) {
var_dump($_FILES);
if (is_uploaded_file($_FILES['userImage']['tmp_name'][0])) {
//require_once "../Matcha-2020-master/config/database.php";
foreach ($_FILES['userImage']['tmp_name'] as $key => $value)
{
// echo $value;
$imgData = addslashes(file_get_contents($value));
$imageProperties = getimageSize($value);
$sql = "INSERT INTO user_images(imageType ,imageData) VALUES('{$imageProperties['mime']}', '{$imgData}'";
if ($firstPic == 0){
$sql = "INSERT INTO user_images(imageType ,imageData, profilePicture) VALUES('{$imageProperties['mime']}', '{$imgData}', 1)";
$firstPic++;
}
// $sql = "INSERT INTO user_images(imageType ,imageData , users_id) VALUES('{$imageProperties['mime']}', '{$imgData}', {$_SESSION['id']})";
try{
$current_id = $conn->prepare($sql);
$current_id->execute();
header("Location: home.php");
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}
}
}
?>