-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsave_img.php
More file actions
47 lines (38 loc) · 1.32 KB
/
save_img.php
File metadata and controls
47 lines (38 loc) · 1.32 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
<?php
session_start();
ob_start();
function generateRandomNumber() {
$randomNumber = '';
for ($i = 0; $i < 8; $i++) {
// Sinh một số ngẫu nhiên từ 0 đến 9 và thêm vào dãy số
$randomNumber .= rand(0, 9);
}
return $randomNumber;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['imageData'])) {
$imageData = $_POST['imageData'];
// Chuyển đổi dữ liệu hình ảnh từ base64 và lưu vào tệp
$name_img='AT_DESIGN_'.generateRandomNumber().'.png';
if(!isset($_SESSION['mat'])){
$_SESSION['mat']=1;
}
if($_SESSION['mat']==1){
$_SESSION['img_front']=$name_img;
$_SESSION['mat']=2;
}else{
if($_SESSION['mat']==2){
$_SESSION['img_back']=$name_img;
unset($_SESSION['mat']);
}
}
$outputFile = 'upload/'.$name_img;
$imageData = str_replace('data:image/png;base64,', '', $imageData);
$imageData = str_replace(' ', '+', $imageData);
$imageData = base64_decode($imageData);
file_put_contents($outputFile, $imageData);
} else {
}
} else {
}
?>