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 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    68
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How do I display images with the include function?

    I am trying to display an image via php include function outside of the root folder of where the php code is.

    The code is:

    PHP Code:
    <?php
    include("/home/rootkbc1/public_html/halo2us/images/carbine.png");
    ?>
    The page with this is in /home/rootkbc1/public_html/mujak/home.php

    So I am trying to get out of the "mujak" directory & into the halo2us directory.

    This code seems to be display a bunch of machine code, meaning its displaying the file but does not know how to interpret it.

    Something with header function~? Just read on it, don't know if this has anything to do with it.

  • #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 are aware that an image cannot actually be displayed with PHP?
    If your intent is to serve it, then yes just push a content type for the image. This script would then become the source for your img tag. This is a waste though since the include is just an image with no dynamic data, so just use the png for your img src instead.
    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 ;)

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    A key thing to remember: PHP is a server side language. It processes data is given, and feeds back text. You format that text as you see fit: html, xml, javascript, etc. But at the end, PHP does nothing on the users end.

  • #4
    New Coder
    Join Date
    Jun 2010
    Posts
    68
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Okay well, what is a good way to display an image outside of the root with php~???

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    You don't display images with PHP... if you're building a webpage, you display images with HTML. So if you mean how do you display images outside the website's directory, you can't. As with any website, you can only display images accessible by the web.

  • #6
    New Coder
    Join Date
    Jun 2010
    Posts
    68
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Are you serious~~!!! I was sure there was something you could use to access an image in a different directory outside its own.

  • #7
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Again... PHP is a server side processing language. It doesn't do magic. It feeds text back to the user, and based on how you define that, it can be HTML, it can be Javascript, it can be XML, etc.

    Now, with HTML, if the image is in another folder that is also accessible to the web (a different domain, a different subdomain, a subfolder), you can access it, like other images on the web. If its not, you can't.

    Now, you could write a PHP script that reads an image, and generates a temporary file in the websites folder. But that would basically be putting an image into the websites folder and linking to it.


  •  

    Posting Permissions

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