Skip to content

Instantly share code, notes, and snippets.

@gustavo-rodrigues-dev
Created May 14, 2013 20:09
Show Gist options
  • Save gustavo-rodrigues-dev/5579073 to your computer and use it in GitHub Desktop.
Save gustavo-rodrigues-dev/5579073 to your computer and use it in GitHub Desktop.
Método que retorna o source da imagem e exibe na view sem renderizar ou salvar o arquivo.
//dataImage
$file = $_FILES['image'];
$image = dataImage($file);
echo '<img src="'.$image.'" />';
/** Return source image
* @param array $file
* @return string Image
*/
public function dataImage($file){
$contents = file_get_contents($file['tmp_name']);
$base64 = base64_encode($contents);
return ('data:' . $file['type'] . ';base64,' . $base64);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment