-
Notifications
You must be signed in to change notification settings - Fork 0
/
Files.php
48 lines (33 loc) · 1.18 KB
/
Files.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
<?php
require_once './Connections.php';
class Filess{
static function upload($width,$height){
if(!isset($_FILES["image"])){
return NULL;
}
$file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$conn=(new Database())->getConnection();
$stmt=$conn->prepare("INSERT INTO images (id) VALUES (NULL)");
$stmt->execute();
$id=$conn->lastInsertId();
$size=getimagesize($file_tmp);
if($size==FALSE){
throw new Exception("It's not an image");
}
if($size[0]!=$width||$size[1]!=$height){
throw new Exception("Sizes don't match");
}
if($file_size > 16*1024*1024){
throw new Exception("File should be less than 16M");
}
if(!move_uploaded_file($file_tmp, "images/".$id)){return false;}
chmod("images/".$id, 0744);
return $id;
}
static function delete($id){
unlink("images/".$id);
}
}