<form method="POST" enctype="multipart/form-data" action=""> <label>Caricare una immagine GIF, JPEG, PNG o ICO</label> <input type="file" name="image"> <input type="submit" name="action" value="Invia"> </form> <?php if (isset($_POST["action"])) { if ($_FILES["image"]['name'] != "") { $fileup = $_FILES["image"]["tmp_name"]; $tp = $_FILES['image']['type']; if (($tp!="image/gif") && ($tp!="image/jpeg") && ($tp!="image/png") && ($tp!="image/x-icon")) { echo "<em>Formato imprevisto. Usare solo formati: GIF, JPEG, PNG o ICO.</em>"; } else { $content = file_get_contents($fileup); $base64 = "data:" . $tp . ";base64," . base64_encode($content); echo "<xmp style='word-wrap:break-word'>" . $base64 . "</xmp>"; } } } ?>
PHP: Image base64 to upload (upload immagine e conversione su codifica base64)
<form method="POST" enctype="multipart/form-data" action=""> <label>Caricare una immagine GIF, JPEG, PNG o ICO</label> <input type="file" name="image"> <input type="submit" name="action" value="Invia"> </form> <?php if (isset($_POST["action"])) { if ($_FILES["image"]['name'] != "") { $fileup = $_FILES["image"]["tmp_name"]; $tp = $_FILES['image']['type']; if (($tp!="image/gif") && ($tp!="image/jpeg") && ($tp!="image/png") && ($tp!="image/x-icon")) { echo "<em>Formato imprevisto. Usare solo formati: GIF, JPEG, PNG o ICO.</em>"; } else { $content = file_get_contents($fileup); $base64 = "data:" . $tp . ";base64," . base64_encode($content); echo "<xmp style='word-wrap:break-word'>" . $base64 . "</xmp>"; } } } ?>