-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
51 lines (48 loc) · 1.74 KB
/
upload.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
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE HTML>
<html>
<body>
<fieldset style="width:300px;">
<legend>Upload to base 64</legend>
<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</fieldset>
</form>
<?php
/*
* Array
(
[file] => Array
(
[name] => logo.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpGyzDJ0
[error] => 0
[size] => 11268
)
)
*/
function getDataURI($image, $mime = '') {
return 'data: ' . $mime . ';base64,' . base64_encode($image);
}
if ($_FILES) {
$fileArray = $_FILES['file'];
$fileLocation = $fileArray['tmp_name'];
$fileData = file_get_contents($fileLocation);
$src = getDataURI($fileData, $_FILES['file']['type']);
echo "<p>Image using base64</p>";
$imgStr = '<img src="' . $src . '">';
echo $imgStr;
echo '<br/>';
echo "<p>Image using base64 To Copy</p>";
$copytext = htmlentities($imgStr);
echo "<textarea cols='100' rows='10' onclick='this.focus();this.select()' readonly='readonly'> $copytext </textarea>";
if (file_exists($fileLocation)) {
unlink($fileLocation);
}
}
?>
</body>
</html>