Created
April 8, 2016 15:54
-
-
Save nbriz/05f62c2e44994dad4b72c03ee38bba9e to your computer and use it in GitHub Desktop.
convert image into base64 encoded string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title> img to data</title> | |
<meta charset="utf-8"> | |
<style> | |
textarea{ width: 50%; height: 200px; } | |
</style> | |
</head> | |
<body> | |
<?php | |
if(isset($_POST["submit"])) { | |
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); | |
if($check !== false) { | |
$data = base64_encode(file_get_contents( $_FILES["fileToUpload"]["tmp_name"] )); | |
echo "copy + paste the data below, use it as a string in ur JavaScript Code<br><br>"; | |
echo "<textarea id='data' style=''>data:".$check["mime"].";base64,".$data."</textarea>"; | |
} else { | |
echo "File is not an image."; | |
} | |
} | |
?> | |
<script>document.getElementById('data').select();</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title> img to data</title> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<form action="convert.php" method="post" enctype="multipart/form-data"> | |
Select image to convert into base64 data: | |
<input type="file" name="fileToUpload" id="fileToUpload"><br> | |
<input type="submit" value="Convert Image to Data" name="submit"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Freaking amazing. You save me a lot of work here.