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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    problem with file_get_contents/images

    I wrote this code and save it in pic1.php

    Code:
    	<?php 
    
    
    
        $path = "http://mysite.com/test.png";
        header('content-type: image/png');
        header ('Cache-Control: no-cache, no-store, max-age=0, s-maxage=0,  must-revalidate');
        header ('Cache-Control: post-check=0, pre-check=0', false);
        header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
        header ('Pragma: no-cache');
        $fgc = file_get_contents ($path);
        print $fgc;
    
    ?>


    and also wrote this code and saved it in pic2.php

    Code:
    <html>
    	<body>
    
    
    <h4>title1</h4>
    <img src="pic1.php" />
    	</body>
    	</html>
    but when I open pic2.php by browser, I can not see any image
    and when open pic1 I just see a blank page

    please somebody help me...whats the wrong?
    Last edited by a306; 02-01-2012 at 12:38 AM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,467
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Can you tell us what the point of doing this is?
    Are you trying to display the image without showing the file location?
    I think PHP GD might be the better approach.

  • #3
    Regular Coder
    Join Date
    May 2007
    Posts
    100
    Thanks
    16
    Thanked 11 Times in 11 Posts
    Assuming the HTTP headers are correct, since you are passing a filename to file_get_contents() have you made sure that fopen wrappers have been enabled? Check the note about that here - http://ca3.php.net/manual/en/functio...t-contents.php

  • Users who have thanked >ssp-cdr< for this post:

    a306 (01-31-2012)

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,467
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Using GD:

    PHP Code:
    <?php
    $path 
    "http://mysite.com/test.png";
    $img imagecreatefrompng($path); // open image
    // output image to browser
    header("Content-type: image/png");
    imagePng($img);
    // clear memory 
    imagedestroy($img);
    ?>

    .

  • Users who have thanked mlseim for this post:

    a306 (01-31-2012)

  • #5
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    hi thanks for the answe

    I removed the empty lines before "<?php" in file pic1.php and it works now!

    my actual code (in pic1) is this:

    Code:
    <?php
    include("../config.php");
    check_log();
    global $db;
    if(!sizeof($_GET))
    {
    $t=user_type();
    if(class_exists($t))
    {
    $pic=new $t();
    $pic=$pic->custome_find("personal_code",user_name(),1);
    $image=base64_decode($pic->get_value('picture'));
    if(strlen($image)>100)
    print $image;
    else
    print file_get_contents(dirname(__FILE__)."/def_pic.png");
    }
    else
    print file_get_contents(dirname(__FILE__)."/def_pic.png");
    }
    else
    {
    $t=$_GET['type'];        
    $id=$_GET['id'];
    $pic=new $t();
    $pic=$pic->custome_find("id",$id,1);
    $image=base64_decode($pic->get_value('picture'));
    if(strlen($image)>100)
    print $image;
    else
    print  file_get_contents(dirname(__FILE__)."/def_pic.png");
    }
    ?>
    but for this code didn't work.


    for test if I replace this line (line 20)

    print file_get_contents(dirname(__FILE__)."/def_pic.png");


    with this:

    {
    $path = 'http://mysite.com/def_pic.png';
    header('content-type: image/png');
    header ('Cache-Control: no-cache, no-store, max-age=0, s-maxage=0, must-revalidate');
    header ('Cache-Control: post-check=0, pre-check=0', false);
    header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    header ('Pragma: no-cache');
    $fgc = file_get_contents ($path);
    print $fgc;
    }


    but it didn't work...
    ( I sure the code in that line works becuase I tested it with a sample code
    Code:
    print "sample text"
    )
    Last edited by a306; 01-31-2012 at 11:32 PM.

  • #6
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    The reson of second error was "include file!"..becuase I saved it with UTF-8!


  •  

    Tags for this Thread

    Posting Permissions

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