Last active
December 17, 2015 04:29
-
-
Save fernandoguedes/5550781 to your computer and use it in GitHub Desktop.
Snippet para transformar campos BLOB (MySQL) em imagens físicas no disco local.
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
<?php | |
mysql_connect("localhost","root","root"); | |
mysql_select_db("db"); | |
$qryBlob = "SELECT data FROM tb_imagens limit 1"; | |
$resBlob = mysql_query($qryBlob) or die('Error, query failed'); | |
while($row = mysql_fetch_array($resBlob)) { | |
$imgEncode = base64_encode($row['data']); | |
$dirImg = 'img/nomedoarquivo.jpg'; | |
$img = imagecreatefromstring(base64_decode($imgEncode)); | |
if($img != false) { | |
imagejpeg($img, $dirImg); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment