-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathupload.php
More file actions
32 lines (27 loc) · 968 Bytes
/
upload.php
File metadata and controls
32 lines (27 loc) · 968 Bytes
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
<?
if(!empty($_FILES["uploadImage"])) {
// get file name
$filename = basename($_FILES['uploadImage']['name']);
// get extension
$ext = substr($filename, strrpos($filename, '.') + 1);
// check for jpg only
if ($ext == "jpg" || $ext == "jpeg" || $ext == "png") {
// generate unique file name
$newName = 'photo_temp/'.time().'.'.$ext;
// upload files
if ((move_uploaded_file($_FILES['uploadImage']['tmp_name'], $newName))) {
// get height and width for image uploaded
list($width, $height) = getimagesize($newName);
// return json data
echo '{"image" : "'.$newName.'", "height" : "'.$height.'", "width" : "'.$width.'" }';
}
else {
echo $_FILES['uploadImage']['name'];
echo '{"error" : "An error occurred while moving the files"}';
}
}
else {
echo '{"error" : "Invalid image format"}';
}
}
?>