Error 500 when including jpg image in PHP page

You can perfectly use any image with the extension .jpg, .png and .gif in a web page. Although there are other extensions, they are less used and less known, or not supported by all browsers, so the recommendation would always be to use .jpg, .png or .gif.

You shouldn’t care what image you use and where you got it from, because all browsers fully understand these image formats. It is something that depends on the browser and not on your programming, PHP or any other language you use on the server side.

Now a 500 error is a server error. That error occurs when the programming of a page is not correct, for whatever reason. The server where you host the page, on Internet servers under your own domain, usually has obfuscated errors, so that no one accessing the server has sensitive information (such as the code used in the programming). That’s why it just throws you a 500 error, something generic.

Well, the fact that you receive a 500 error makes me understand that something in the programming you are doing is incorrect. I mean server side programming, which you have in the PHP code of files with .php extension. Usually when you put an image on the page you do it from an HTML tag, so if you’re doing things right, you shouldn’t get a 500 error even if the image was corrupted. In any case, the normal thing would be that the browser could not show it to you.

Therefore, I am inclined to think that the problem could be caused by one of these possibilities:

  • You have changed the extension of the image to .php and because of this the server tries to process the image file as if it were PHP code. You must make sure that the extension is one of those allowed in the image, .jpg would be correct, but it would also be .png or .gif. Each format has its encoding, so the image would have to have the corresponding file extension.
  • The code in the tag may have some PHP open code (
See also  Where we put the Javascript functions

If you verified the above, I would try to open your image with an image editing program on your computer, and save it again, in a new file, with one of the accepted formats for the web.

If the image has a problem, the design program still prevents you from opening it, which would help you understand what is happening. Then, when you save the image or export it to some format allowed for the web, the image editing program will create the image again with an accepted and correct format, so you shouldn’t have any problems. Notice again using the .

Loading Facebook Comments ...
Loading Disqus Comments ...