SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,316
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    file_get_contents not always working

    I notice that the following code is correctly pulling the file contents:

    PHP Code:
    $file '../includes_html/'.$PartNo.'.htm';
    if(
    file_exists($file))
        {
        echo 
    file_get_contents($file);
        } 
    However, for a couple pages the code does not work. I have an html page with a jpg photo and a text caption underneath. Only the caption shows. The jpg does not show up - just a paragraph space where it should be. If I open the html page separately, I can see the image and caption plainly. Since the caption shows up, the URL is correct.

    Are there some exceptions that prevent the file_get_contents code from working? It correctly shows text and images on other pages. I'm puzzled that it has not worked with the last two pages I uploaded. Here's the html page where the jpg does not show up:

    Code:
    <body>
    <p align="center">
    <img src="89442_decal_files/89442_decal.jpg" /></p>
    <p align="center">
    Decal Sheet included
    </p>
    
    </body>
    Adding the DOCTYPE to the top did not make any difference.

    Thanks!

  2. #2
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StevenHu View Post
    I notice that the following code is correctly pulling the file contents:

    PHP Code:
    $file '../includes_html/'.$PartNo.'.htm';
    if(
    file_exists($file))
        {
        echo 
    file_get_contents($file);
        } 
    However, for a couple pages the code does not work. I have an html page with a jpg photo and a text caption underneath. Only the caption shows. The jpg does not show up - just a paragraph space where it should be. If I open the html page separately, I can see the image and caption plainly. Since the caption shows up, the URL is correct.

    Are there some exceptions that prevent the file_get_contents code from working? It correctly shows text and images on other pages. I'm puzzled that it has not worked with the last two pages I uploaded. Here's the html page where the jpg does not show up:

    Code:
    <body>
    <p align="center">
    <img src="89442_decal_files/89442_decal.jpg" /></p>
    <p align="center">
    Decal Sheet included
    </p>
    
    </body>
    Adding the DOCTYPE to the top did not make any difference.

    Thanks!
    The image paths are probably wrong.

    Go to one of the pages where it shows correctly with file_get_contents(), and then open that page up separately, does it still work?
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think this is because the path you have given to the image. Try giving a full path (url) to the image in your reading file/page. Or give the path for the page in which you are going to echo that content.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,316
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I opened up a page that showed the file contents correctly and checked the page source. It actually had an extra folder name (higher up) in the URL for the images. I added that folder name to the SRCs URL and now the two new pages work.

    Thanks!


Bookmarks

Posting Permissions

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