php - How do I load an svg from a folder outside http while hiding location -
on of our sites keep images outside main http folder because people logged in can see these images. have function wrote ages ago loads images outside http folder , scrambles location cannot see loaded from, , works jpg , png. problem have started using svg images, , same code not work @ svg. question how change code make work svg well?
function show_picture($location,$file) { $location=$location.$file; if ( file_exists($location) ) { $imagedata = base64_encode(file_get_contents($location)); $finfo = new finfo(); $fileinfo = $finfo->file($location, fileinfo_mime); $src = 'data: '.$fileinfo.';base64,'.$imagedata; echo'<img class="picture" src="'.$src.'" alt="part picture" /></a>'; } else { echo'<img class="picture" src="images/nopicture.jpg" alt="part picture not exist" /></a>'; } }
i adding little more detail in hope of getting answer. wrote litte code find out finfo() bringing mime , showing text/html; charset=us-ascii when mime should bringing 'image/svg+xml'. reason mime not working correctly on svg.
$image="../images/logo.svg"; $finfo = new finfo(); $fileinfo = $finfo->file($image, fileinfo_mime); echo "test:".$fileinfo;
i know definately mime problem because replaced line in originaly code from
$fileinfo = $finfo->file($image, fileinfo_mime);
to
$fileinfo ="image/svg+xml";
and shows svg, not ideal way of doing it, not images svg. unless put if statement in. defeats object of using mime though.
Comments
Post a Comment