-
Notifications
You must be signed in to change notification settings - Fork 73
/
upload.php
33 lines (29 loc) · 842 Bytes
/
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
<?php
/*
PekeUpload
Copyright (c) 2013 Pedro Molina
*/
// Define a destination
$targetFolder = 'uploads/'; // Relative to the root
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname(__FILE__) . '/' . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['file']['name'];
// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['file']['name']);
$response = array ();
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
$response['success'] = 1;
foreach ($_POST as $key => $value){
$response[$key] = $value;
}
echo json_encode($response);
} else {
$response['success'] = 0;
$response['error'] = 'Invalid file type.';
echo json_encode($response);
}
}
?>