-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
38 lines (32 loc) · 1.26 KB
/
upload.php
File metadata and controls
38 lines (32 loc) · 1.26 KB
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
<?php
session_start();
$ds = DIRECTORY_SEPARATOR; //1
//todo get original file size and then get file size of resize, save to file for use in view
$storeFolder = 'uploads/' . $_SESSION['folder'];
if(!is_dir($storeFolder)){
mkdir($storeFolder);
}
if (!empty($_FILES)) {
print_r($_FILES);
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$targetFile = $targetPath. $_FILES['file']['name'];
$resizeName = $targetPath . explode(".",$_FILES['file']['name'])[0];
//move_uploaded_file($tempFile,$targetFile);
$resize = new Imagick($tempFile);
if(!empty($_POST['resize'])){
//Not empty we should resize the image
$resize->resizeImage($_POST['size'],$_POST['size'],Imagick::FILTER_LANCZOS,1);
}
//dont resize but optimise. convert to jpg and lower quality
$resize->stripImage();
$resize->setImageCompression(imagick::COMPRESSION_JPEG);
$resize->setImageCompressionQuality(80);
if(!empty($_POST['progressive'])){
//make image progressive
$resize->setInterlaceScheme(imagick::INTERLACE_PLANE);
}
$resize->writeImage($resizeName . '.jpg');
$resize->destroy();
}
?>