I’m converting an image upload to base64, but I’m also trying to not have to store the image on my server unfortunately this code stores the file on my server is there a way to have it delete the file after it it encoded to base64?
Here is my code..
if(isset($_FILES['t1']['name'])){
$file = rand(0, 10000000).$_FILES['t1']['name'];
if (move_uploaded_file($_FILES['t1']['tmp_name'], $file)) {
if($fp = fopen($file,"rb", 0))
{
$picture = fread($fp,filesize($file));
fclose($fp);
// base64 encode the binary data, then break it
// into chunks according to RFC 2045 semantics
$base64 = base64_encode($picture);
$tag1 = '<img src="data:image/png;base64,'.$base64.'" alt="" />';
$css = 'url(data:image/png;base64,'.str_replace("\n", "", $base64).'); ';
}
}
}
Use https://www.php.net/manual/en/function.unlink.php
so