-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
89 lines (76 loc) · 2.87 KB
/
upload.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
require_once 'myAutoLoader.php';
require_once 'vendor/autoload.php';
use Intervention\Image\ImageManagerStatic as Image;
Image::configure(array('driver' => 'gd'));
use ColorThief\ColorThief;
session_start();
if (!isset($_SESSION['user']))
{
header("Location:access_refused.php");
exit;
}
if(isset($_POST["upload"]))
{
$fileCount = count($_FILES["fileToUpload"]['name']);
for ($i = 0; $i < $fileCount; $i++)
{
$relativePath = $_FILES['fileToUpload']['name'][$i];
$absolutePath = $_FILES['fileToUpload']['tmp_name'][$i];
if (Tools::isAnImage($absolutePath) === false)
$_SESSION['errorUpload'] = 'Erreur, un ou plusieurs fichiers ne sont pas des images.';
else
{
try
{
$path = Tools::saveImage($_SESSION['user']->dir, $absolutePath, $relativePath);
$img = Image::make($absolutePath)->resize(420, 420)->save($_SESSION['user']->dir . $path);
$dominantColor = ColorThief::getColor($_SESSION['user']->dir . $path);
$prepare = myPDO::getInstance()->getConnection()->prepare('insert into images(name, userId, red, green, blue) values(:name,:userId, :red, :green, :blue)');
$prepare->execute(array('name' => $path, 'userId' => $_SESSION['user']->id, 'red' => $dominantColor[0], 'green' => $dominantColor[1], 'blue' => $dominantColor[2]));
}
catch (Exception $e)
{
$_SESSION['error'] = 'Une erreur est survenue, veuillez réessayer ulterieurement.';
}
}
}
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>420px - Importer une image</title>
<link rel="stylesheet" href="css/bulma.css">
<link rel="stylesheet" href="css/custom.css">
</head>
<body>
<?php
include "header.php";
?>
<div class="hero-body">
<div class="container has-text-centered">
<?php
include "error.php"
?>
<h2 class="title">
Import d'image
</h2>
<form method="post" enctype="multipart/form-data">
<input type="file" id="fileToUpload" name="fileToUpload[]" class="inputfile" data-multiple-caption="{count} files selected" multiple />
<label for="fileToUpload">
<img src="img/upload.png" width=30 height=22/>
<span>Choose a file…</span>
</label>
<div class="field">
<button type="submit" name="upload" class="button is-primary">Importer</button>
</div>
</form>
</div>
</div>
<script src="js/custom-file-input.js"></script>
</body>
</html>