-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimgServer.php
More file actions
59 lines (52 loc) · 1.64 KB
/
imgServer.php
File metadata and controls
59 lines (52 loc) · 1.64 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
header('Content-Type: application/json; charset=utf-8');
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: PUT, GET, POST");
include_once 'dbh.inc.php';
$response = array();
$DIR = 'uploads/';
$urlServer = 'http://127.0.0.1/api';
if($_FILES['image'])
{
$fileName = $_FILES["image"]["name"];
$tempFileName = $_FILES["image"]["tmp_name"];
$error = $_FILES["image"]["error"];
if($error > 0){
$response = array(
"status" => "error",
"error" => true,
"message" => "Error uploading the file!"
);
}else
{
$FILE_NAME = rand(10, 1000000)."-".$fileName;
$UPLOAD_IMG_NAME = $DIR.strtolower($FILE_NAME);
$UPLOAD_IMG_NAME = preg_replace('/\s+/', '-', $UPLOAD_IMG_NAME);
if(move_uploaded_file($tempFileName , $UPLOAD_IMG_NAME)) {
$response = array(
"status" => "success",
"error" => false,
"message" => "Image has uploaded",
"url" => $urlServer."/".$UPLOAD_IMG_NAME
);
$uid = $_POST['uid'];
$ppurl = $urlServer."/".$UPLOAD_IMG_NAME;
$sql = "UPDATE users SET uImage='$ppurl' WHERE uidUsers='$uid';";
mysqli_query($conn, $sql);
}else
{
$response = array(
"status" => "error",
"error" => true,
"message" => "Error occured"
);
}
}
}else{
$response = array(
"status" => "error",
"error" => true,
"message" => "File not found"
);
}
echo json_encode($response);