How can I use php to display an image file?

by on January 8, 2010

Q: How can I use PHP to generate complex images from a file? I have a public_html folder on the root of my webhost filesystem. I also created a private_data folder for sensitive information, such as bio profiles. I have the profile picture stored in the private_data/Registration/Profiles/USERNAME/Picture.jpg but because that folder is not accessible on the web, the IMG SRC tag doesn’t work. How can I say something like “img src=blah.php” and the php file actually loads the profile picture? All i understand so far is how to create backgrounds and plaintext into an image. But how do I load a preexisting image file?

Read Answer Here

3 Responses to “How can I use php to display an image file?”

    Okay, I googled it and within 1 minute had the answer, within another 3 minutes, typed it out and tested it. it works

    Picked as best answer

    $myImage = imagecreatefromjpeg(‘jpgFile.jpg’);
    header(“Content-type: image/jpeg”);


    Yeah sorry about the slow reply. I was thinking you could just do a file_get_contents() and just set the header but I didn’t have time to test it to make sure. I was actually just getting to it but I am certainly glad you were able to find a solution on your own.