Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $src = '';
- if (ISSET($_FILES['upload'])) {
- // get file data from upoad
- // http://php.net/manual/en/reserved.variables.files.php#89674
- $data = $_FILES['upload']['tmp_name'];
- // file_get_contents — Reads entire file into a string
- // base64_encode — Encodes data with MIME base64
- $base64 = base64_encode(file_get_contents($data));
- // mime_content_type — Detect MIME Content-type for a file
- $type = mime_content_type($data);
- $src = '<img src="data:'.$type.';base64,'.$base64.'"/>';
- }
- ?>
- <!DOCTYPE html>
- <head>
- </head>
- <body>
- <form action="" method="post" enctype="multipart/form-data">
- Select image to upload:
- <input type="file" name="upload">
- <input type="submit" value="Upload Image" name="submit">
- </form>
- <?php echo $src; ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement