Advertisement
michaelyuen

Untitled

Jul 6th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. <?php
  2.     $src = '';
  3.     if (ISSET($_FILES['upload'])) {
  4.         // get file data from upoad
  5.         // http://php.net/manual/en/reserved.variables.files.php#89674
  6.         $data = $_FILES['upload']['tmp_name'];
  7.         // file_get_contents — Reads entire file into a string
  8.         // base64_encode — Encodes data with MIME base64
  9.         $base64 = base64_encode(file_get_contents($data));
  10.         // mime_content_type — Detect MIME Content-type for a file
  11.         $type = mime_content_type($data);
  12.         $src = '<img src="data:'.$type.';base64,'.$base64.'"/>';
  13.     }
  14. ?>
  15. <!DOCTYPE html>
  16. <head>
  17. </head>
  18. <body>
  19. <form action="" method="post" enctype="multipart/form-data">
  20.     Select image to upload:
  21.     <input type="file" name="upload">
  22.     <input type="submit" value="Upload Image" name="submit">
  23. </form>
  24. <?php echo $src; ?>
  25. </body>
  26. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement