www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] error when including an image | Unexpected character

Threaded View

  1. #1
    Join Date
    Oct 2007
    Posts
    371

    resolved [RESOLVED] error when including an image | Unexpected character

    I am in unfamiliar territory.
    I am using an API to access data from a service. In an effort to take some of the load off the service and onto our server, we are caching the images.
    Here's a snippet that either pulls from cache or writes the new one to cache.
    PHP Code:
    if(file_exists($fullpath)){
    //$contents=file_get_contents($fullpath);
    //echo $contents;
    include($fullpath);
    }
    else{
    $urlREDACTED;
    save_image($url,$fullpath);
    include(
    $fullpath);

    The else portion used to be
    PHP Code:
    $urlREDACTED;
    echo(
    save_image($url,$fullpath)); 
    The save_image function uses cURL to access an image from the service at $url. I set it to return the raw data when I tried the echo version.

    At first it didn't occur to me that including the jpg would work, so I used file_get_contents. I noticed it was slow, so I wanted to speed it up. I tried incude and I got various error messages on 3 of the 49 images in my test query. the errors were like this:
    Code:
    Parse error: syntax error, unexpected '~' in /home/user/...###thumbs.jpg on line 7
    
    Warning: Unexpected character in input: '' (ASCII=14) state=1 in /home/user/public_html/...###thumbs.jpg on line 9
    Parse error: syntax error, unexpected T_STRING in /home/user/public_html/...###thumbs.jpg on line 9
    
    and 
    
    Warning: Unexpected character in input: '' (ASCII=22) state=1 in /home/user/...###thumbs.jpg on line 8
    Parse error: syntax error, unexpected T_STRING in /home/user/...###thumbs.jpg on line 8
    My guess is that I need to find a way to tell it not to parse, even though it is being included. Include seems to be much faster than file_get_contents, so I'd like to stick with it if I can.
    Last edited by TecBrat; 10-29-2010 at 02:06 AM. Reason: fix typos

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
HTML5 Development Center



Recent Articles