-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
50 lines (47 loc) · 1.71 KB
/
index.php
File metadata and controls
50 lines (47 loc) · 1.71 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Uplaod to ImageBB</title>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<input type="file" name="record_image" accept="image/*">
<button type="submit">Get Link</button>
</form>
<?php
function save_record_image($image, $name = null)
{
$API_KEY = '......................';
//Get Api Key From https://api.imgbb.com/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.imgbb.com/1/upload?key=' . $API_KEY);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$extension = pathinfo($image['name'], PATHINFO_EXTENSION);
$file_name = ($name) ? $name . '.' . $extension : $image['name'];
$data = array('image' => base64_encode(file_get_contents($image['tmp_name'])), 'name' => $file_name);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
if (curl_errno($ch)) {
return 'Error:' . curl_error($ch);
} else {
return json_decode($result, true);
}
curl_close($ch);
}
if (!empty($_FILES['record_image'])) {
$image_data = save_record_image($_FILES['record_image'], 'test');
$image = $image_data['data'];
echo 'Main Image : ' . $image['image']['url'];
echo '<br>';
echo 'thumb Image : ' . $image['thumb']['url'];
echo '<br>';
echo 'medium Image : ' . $image['medium']['url'];
echo '<br>';
}
?>
</body>
</html>