PHP : Unexpected T_String while including jpeg image
When including an image file in a php page using
include "images/filename.jpg";
I get the following error
Parse error: syntax error, unexpected T_STRING in path_to_folder/images/filename.jpg on line 1
whereas this is working locally on 开发者_C百科my local wamp server. My site is hosted on hostmonster -- which I guess provides php5. Could the problem be with the host ?
As the other answers say, you are trying to execute the image (binary data) as php code. This is probably what you want:
header('Content-Type: image/jpeg');
readfile('image.jpeg');
This code doesn't make sense, and I don't see why it would work locally. You're telling PHP to execute the image as PHP/HTML code, which will not work.
You're missing quotes around the file path, anyway including an image in the code makes no sense. I can't imagine how it could work locally.
you just don't understand what are you doing.
include
is used for including another part of PHP code into your script.
To output a file you have to use readfile()
instead
Is it possible that your jpeg contains the sequence <?
? Include is not meant to be used like this. You should use file_get_contents instead:
echo file_get_contents("images/filename.jpg");
精彩评论