-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile.php
More file actions
19 lines (16 loc) · 780 Bytes
/
Copy pathmakefile.php
File metadata and controls
19 lines (16 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])) {
// Get the data
$imageData = $GLOBALS['HTTP_RAW_POST_DATA'];
// Remove the headers (data:,) part.
// A real application should use them according to needs such as to check image type
$filteredData = substr($imageData, strpos($imageData, ",") + 1);
// Need to decode before saving since the data we received is already base64 encoded
$unencodedData = base64_decode($filteredData);
// Save file. This example uses a hard coded filename for testing,
// but a real application can specify filename in POST variable
//$fp = fopen("images/genimg".date("YmdHis").".png", 'w');
$fp = fopen("images/img_" . microtime(1) . ".png", 'wb');
fwrite($fp, $unencodedData);
fclose($fp);
}