-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuploade.php
More file actions
32 lines (26 loc) · 1.08 KB
/
uploade.php
File metadata and controls
32 lines (26 loc) · 1.08 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
<?php
if (!empty($_FILES)) {
$tempPath = $_FILES['Filedata']['tmp_name'];
$uploadPath = dirname(__FILE__) . '\uploads\\' . $_FILES['Filedata']['name'];
move_uploaded_file($tempPath, $uploadPath);
$answer = array('filename' => 'uploads/'.$_FILES['Filedata']['name'], 'success' => true, 'data' => $_POST['test']);
echo json_encode($answer);
} else {
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
if ($request['photo']) {
$img = str_replace('data:image/png;base64,', '', $request['photo']);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = dirname(__FILE__) . '\uploads\\' . uniqid() . '.png';
$success = file_put_contents($file, $data);
if ($success) {
$answer = array('filename' => 'uploads/'.$_FILES['Filedata']['name'], 'success' => true);
} else {
$answer = array('answer' => 'Не фига не вышло!');
}
} else {
$answer = array('answer' => 'no files');
}
echo json_encode($answer);
}