Welcome Guest, Not a member yet? Register   Sign In
Loading an image into a View.
#1

I have some image files in ROOTPATH."writable/users/ which I am trying to display in the user's browser.
My Routes.php contains the line:$routes->get('/loadthumbs/(:any)', 'ThumbController::loadthumbimage/$1');
PHP Code:
<?php
namespace App\Controllers;
use 
CodeIgniter\Controller;

class 
CrudController extends BaseController {
 public function 
loadthumbimage($img){
    $uri service('uri');
 
$segments=$uri->getSegments();
    $previewpath=ROOTPATH."writable/users/".$segments[1]."/".$segments[2];
    $header="Content-Type: image/".substr($segments[2],-3);
    header($header);
        header("Content-Length: " filesize($previewpath));
    $fp fopen($previewpath'rb');
    fpassthru($fp);
    exit;
    }
}
?>
 In this instance, the image is a .BMP file, so the header is $header="Content-Type: image/bmp";
The image file is fine and opens locally with no problem, but it doesn't display in the bowser.
Instead I get a message 
Code:
The image "https://example.com/loadthumbs/8/1.bmp" cannot be displayed because it contains errors.
If I google this error, I get advice about making sure not to have a whitespace between the '<?php' marker at the start of the file and the header directives, but clearly this is not possible here.
Can anyone suggest a solution?
~ Dave
Reply
#2

See my post under the "Best Practices" subforum.
~ Dave
Reply




Theme © iAndrew 2016 - Forum software by © MyBB