Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts

    Showing an image

    Can someone help me display an image, I don't know how

    PHP Code:
    <?php    
    // Work around the Flash Player Cookie Bug
        
    if (isset($_POST["PHPSESSID"])) {
            
    session_id($_POST["PHPSESSID"]);
        }
        
        if(isset(
    $_GET['id']) && isset($_GET['type'])){
            
    mysql_connect('localhost''root''');
            
    mysql_select_db('ludatha_base');
            
            
    $id $_GET['id'];

            
    $sql "SELECT * FROM images WHERE code = '$id'";     

            
    $result mysql_query($sql);
            
            
    $linkege=mysql_fetch_array($result);
            
            if(
    $_GET['type'] == 'pic'){
                
    $file 'upload/1/pictures/' $linkege['file'];    
            }else{ 
                
    $file 'upload/1/pictures/' $linkege['thumb'];
            }
            
              
    header('Content-Type: image/jpeg');
            
    header('Content-Disposition: inline; filename=' $file '.jpg');
            echo 
    $file;
        }
    ?>
    $linkege['file'] gets the file name of the image

    Thanks in advance!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You got to read the file and print out the contents of it:
    PHP Code:
    if (false !== ($fh fopen($file'rb')))
    {
        if (
    false !== ($fr = @fread($fhfilesize($file))))
        {
            
    header('Content-type: image/jpeg');
            echo 
    $fr;
        }

    Try something like this in place of what you have at the end.
    Last edited by Fou-Lu; 11-29-2008 at 05:43 PM. Reason: Added binary mode in case its windows used
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    Ludatha (11-30-2008)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •