-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite.php
41 lines (27 loc) · 912 Bytes
/
write.php
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
<?php
if($_POST[img]){
$output_file = 'img_'.time().'.jpg';
base64_to_jpeg($_POST[img], $output_file);
echo $output_file;
}else{
$stuff = str_replace("\"", "'", $_POST[x] );
$text = preg_replace("/\r|\n/", "", $stuff);
$content = '{"html":"'. $text.'"}';
$file = __DIR__."/files/".$_POST[id].".json";
$Saved_File = fopen($file, 'w');
fwrite($Saved_File, $content);
fclose($Saved_File);
}
function base64_to_jpeg($base64_string, $output_file) {
// open the output file for writing
$ifp = fopen( __DIR__."/files/".$output_file, 'wb' );
// split the string on commas
// $data[ 0 ] == "data:image/png;base64"
// $data[ 1 ] == <actual base64 string>
$data = explode( ',', $base64_string );
// we could add validation here with ensuring count( $data ) > 1
fwrite( $ifp, base64_decode( $data[ 1 ] ) );
// clean up the file resource
fclose( $ifp );
return $output_file;
}