Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make PHP page as an image in return

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 118
    Comment on it

    Hello Reader's If you have to return a image from PHP page. then you can use the code as written below:-

    <?php
    // open the file in a binary mode
    $name = './img/ok.png';
    $fp = fopen($name, 'rb');
    
    // send the right headers
    header("Content-Type: image/png");
    header("Content-Length: " . filesize($name));
    
    // dump the picture and stop the script
    fpassthru($fp);
    exit;
    ?>
    

    Now you just have to remember that you must send a Content-Type header. Also don't leave any white spaces just after or before <?php ?> tags then only it will return image.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: