-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFileUploader.php
More file actions
39 lines (30 loc) · 1.17 KB
/
Copy pathFileUploader.php
File metadata and controls
39 lines (30 loc) · 1.17 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
39
<?php
$targetPath = "uploads/";
$response = array();
$FileURL = "http://".gethostbyname(gethostname())."/KrystianKl/API/v1/".$targetPath;
if(!is_dir($targetPath)) mkdir($targetPath);
if(isset($_FILES["UImage"]["name"])) {
$targetPath = $targetPath.basename($_FILES["UImage"]["name"]);
$UserID = isset($_POST["UserID"]) ? $_POST["UserID"] : "";
$EMail = isset($_POST["EMail"]) ? $_POST["EMail"] : "";
$response["file_name"] = basename($_FILES["UImage"]["name"]);
$response["UserID"] = $UserID;
$response["EMail"] = $EMail;
try {
if (!move_uploaded_file($_FILES["UImage"]["tmp_name"], $targetPath)) {
$response["error"] = true;
$response["message"] = "Nie można przestawić pliku!";
}
$response["message"] = "Pomyślnie wgrano plik!";
$response["error"] = false;
$response["file_path"] = $FileURL.basename($_FILES["UImage"]["name"]);
} catch (Exception $e) {
$response["error"] = true;
$response["message"] = $e->getMessage();
}
} else {
$response["error"] = true;
$response["message"] = "Nie przesłano żadnego pliku!";
}
echo json_encode($response);
?>