Created
October 12, 2013 03:36
-
-
Save azcdev/6945508 to your computer and use it in GitHub Desktop.
Script en PHP para extraer imagenes de cadenas de texto
This file contains hidden or 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 | |
function extraerImagen($cadenaDeTexto, $encabezado, $pieDeArchivo){ | |
$ini = strpos($cadenaDeTexto, $encabezado); | |
if ($ini == 0) return false; | |
$lon = strpos($cadenaDeTexto,$pieDeArchivo, $ini); | |
return substr($cadenaDeTexto,$ini,$lon); | |
} | |
$archivo = 'fileCarvingTest.docx'; | |
$buffer = fread(fopen($archivo, "r"), filesize($archivo)); | |
$imagen = extraerImagen(bin2hex($buffer), "ffd8", "ffd9"); | |
if($imagen) { | |
file_put_contents('imagenExtraida.jpg',hex2bin($imagen)); | |
} else { | |
echo "Imagen no encontrada"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment