[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.
The else portion used to be
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:
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.
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
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
Last edited by TecBrat; 10-29-2010 at 01:06 AM.
Reason: fix typos
Your errors are from include trying to parse the jpg image as PHP. You can include HTML files because they can be parsed as PHP but not images.
Have you tried:
This avoids the intermediate variable which in theory should increase its response.
Leslie Liew - Web Developer
As I was typing my question, I thought about skipping the variable and putting file_get_contents directly in the echo, but I haven't tried it. (It was way past my bed-time when I posted that. )I'll let you know how it goes.
Thanks for the suggestion. I tried it and it seems to be faster than my original method, and obviously fixes the error I was getting.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread