-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
30 lines (30 loc) · 1.33 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
<?php
/**
* Handel the uploaded files
*/
// Point to a safe and secure path to upload the files
$secureDirectory = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR;
// Point to a directory where the (temporary) resizes images will be saved. Change the url below if you change this
$cacheDirectory = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
$output = '0';
if (isset($_FILES['filename']) && !empty($_FILES['filename']) && isset($_FILES['filename']['name'][0])) {
foreach ($_FILES['filename']['name'] as $index => $name) {
$file = array();
$file['name'] = $_FILES['filename']['name'][$index];
$file['type'] = $_FILES['filename']['type'][$index];
$file['tmp_name'] = $_FILES['filename']['tmp_name'][$index];
$file['error'] = $_FILES['filename']['error'][$index];
$file['size'] = $_FILES['filename']['size'][$index];
if(isset($file['name']) && !empty($file['name'])) {
if($file['error'] === 0 && $file['type'] == 'image/jpeg') {
$filename = uniqid() .'.jpg';
$filepath = $secureDirectory . $filename;
if(move_uploaded_file($file['tmp_name'], $filepath)) {
$output = '1';
}
}
}
}
}
echo $output;
exit;