-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuploader.php
41 lines (26 loc) · 1.04 KB
/
uploader.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
<?php
require_once('ImageManipulator.php');
$id = $_SESSION['id'];
$user_directory = 'uploads/'.$id;
// If the file is sent, create a directory with the users' ID. //
if (isset($_FILES['file']['name'])) {
$image_name = $_FILES['file']['name'];
$image_name = str_replace(' ', '_', $image_name);
}
if (!file_exists($user_directory)) {
mkdir($user_directory, 0777, true);
}
// If a file is sent, check that it's an image. //
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$validExtensions = array('.jpg', '.jpeg', '.gif', '.png');
$fileExtension = strrchr($_FILES['file']['name'], ".");
if (in_array($fileExtension, $validExtensions)) {
// Call the ImageManipulator and set height/width to 960*540px. //
$manipulator = new ImageManipulator($_FILES['file']['tmp_name']);
$newImage = $manipulator->resample(960, 540);
// Save the edited image to the users' folder. //
$manipulator->save('uploads/' . $id . '/' . $image_name . $_FILES['fileToUpload']['name']);
}
}
?>