output image via php problems -
output image via php problems -
i aware trivial problem can't seem right although have spent lastly few hours crawling web..
i have file image_get.php supposed display image file "keepcalm.png" located in same directory php file.
i using class handle image related actions.
image_get.php
<?php include "classes/image.class.php"; include "classes/database.class.php"; $database_sso = new database('sso'); //will needed later , dummy $testimage = new image($database_sso, "1"); //parameters dummy $testimage->show_image(); ?>
image.class.php
<?php class image{ private $database_image; //image database containing images private $imageid; //id of image in database private $filepath; //path image file //public functions public function __construct($database, $imageid){ $this->database_image = $database; //right placeholder $this->imageid = $imageid; //right placeholder } public function show_image(){ $remoteimage = $this->get_local_link_from_id($this->imageid); // right returns "keepcalm.png" header('content-type: image/x-png') $returnstring = readfile($remoteimage); } //private functions private function get_local_link_from_id($imageid){ $local_link = "keepcalm.png"; //dummy homecoming $local_link; } } ?>
the output complet gibberish can seen here -> http://niederrad.no-ip.org/portal/image_get.php
what missing? have tried lots of iterations of above , clueless how should proceed..
try this:
public function show_image() { // returns "keepcalm.png" $remoteimage = $this->get_local_link_from_id($this->imageid); // set header header("content-type: image/png"); // more info: http://stackoverflow.com/a/2086406/2332336 // output contents of image readfile($remoteimage); exit; }
if doesn't work you, means php not able locate local image keepcalm.png
perchance because doesn't exist here: http://niederrad.no-ip.org/portal/keepcalm.png
(i.e. script (image_get.php
) execution location http://niederrad.no-ip.org/portal/
)
if case, might have tell readfile()
command image located on server. mean specify absolute path file (on linux server /home/username/public_html/images/
example)
if image on remote server (as variable name suggests), code should this:
// output contents of image exit(file_get_contents('http://remote-site.com/path/to/'. $remoteimage));
assuming php config has allow_url_fopen
set true.
php image readfile
Comments
Post a Comment