error ouput opening a picture file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bytesc
    New Member
    • Aug 2008
    • 7

    error ouput opening a picture file

    Hey guys,

    I have created many picture files using gd_library, I recently decided to rename all of my pictures files on my web server to text instead of just numbers.
    Example: productsssh.jpg

    I am recently receiving a wierd error when I open up some of the picture files. Here is the name of the picture: productsssh.jpg .

    I get the following error only when i open up that picture via the web:


    Warning: Unexpected character in input: '' (ASCII=24) state=1 in /home/virtual/site1/fst/var/www/html/pics/productsssh.jpg on line 15

    Warning: Unexpected character in input: ' in /home/virtual/site1/fst/var/www/html/pics/productsssh.jpg on line 15

    Parse error: syntax error, unexpected T_STRING in /home/virtual/site1/fst/var/www/html/pics/productsssh.jpg on line 15
    When i rename the file to "producsssh.jpg " it opens up perfectly fine.

    I don't know why i am getting an apache or php error when attempting to open the file. Second, I don't know why i am getting the error only when i try to view the file over the web via my server. If I actually download the file I can perfectly open it via my computer.

    My webserver is a linux box redhat.

    All I am doing is opening up a picture file via the web... why am i receinving a php or apache error.... where is the error coming from?

    Any help regarding this matter would be greatly appriciated.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Bytesc.

    When you name your image file with a '.php' extension, Apache is trying to execute it as a PHP script, which is generating all those errors.

    Comment

    • bytesc
      New Member
      • Aug 2008
      • 7

      #3
      No the pictures are not witht he php extension. ALl the pictures are jpeg example: productssh.jpg.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by bytesc
        No the pictures are not witht he php extension. ALl the pictures are jpeg example: productssh.jpg.
        This isn't a PHP problem then.

        I suggest you ask in the Apache forum.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Originally posted by bytesc
          No the pictures are not witht he php extension. ALl the pictures are jpeg example: productssh.jpg.
          Given the warnings it is showing you, it looks like your HTTP server is trying to execute the images as PHP code, which is highly unusual unless you have been messing around with the server's configuration.

          Have you been doing anything like that?
          Are your images being called via some PHP code, or simply being fetched the old fashion way, via a public URL?

          Comment

          • bytesc
            New Member
            • Aug 2008
            • 7

            #6
            I haven't played around with any of my settings and no I am simply calling up the pictures by directly, example:

            http://www.site.com/pics/pictures.jpg

            Maybe somehow, apache is reading the jpg files as php which is very strange and does not happen when my pictures are in number name format. example 112233.jpg

            By the way this only happens to pictures that i have created with php gd library, via php.

            This is very strange, I am really confused!

            Comment

            • Atli
              Recognized Expert Expert
              • Nov 2006
              • 5062

              #7
              Ok.

              That is strange. Your HTTP server should not be executing that as PHP code, unless it is told to do so.

              The name of the file shouldn't make a difference. Whether they are alpha-numeric or strictly a numeric string, it shouldn't have any effect on how the server handles them.

              Seeing as this is only happening to PHP generated images, I would guess the problem is there.
              Could you show us the code that you used to create them?

              Comment

              • bytesc
                New Member
                • Aug 2008
                • 7

                #8
                Here is the code I have used to create the picture:

                [PHP]
                $i = http://www.site.com/pic1.jpg
                $ni = "/home/virtual/site1/var/www/html/pics/new_pic.jpg";
                if (!$img=@imagecr eatefromjpeg("$ i")) {
                die;
                }

                $newimg=imagecr eatetruecolor(1 00,100);
                $bgColor = imagecoloralloc ate($newimg, 255,255,255);
                imagefill($newi mg,0,0,$bgColor );
                imagecopyresamp led($newimg,$im g,0,0,0,0,100,1 00,100,100);
                imagejpeg($newi mg, $ni);
                [/PHP]

                The thing is I have been using this code for almost 1 year and never had a single error like the one I am facing now. As soon as I decided to name the file text names the error starting happening.

                By the way thanking for taking the time to help me debug this issue.

                Comment

                • Atli
                  Recognized Expert Expert
                  • Nov 2006
                  • 5062

                  #9
                  Ok. I can't see why that would cause problems. Seems perfectly fine to me.

                  Which brings us back to your HTTP server.

                  Do you have use any .htaccess files in your site?
                  Could this be some url_rewrite fluke?

                  I've heard of instances where JPEG images have been used to execute malicious code on a PHP server.
                  I guess that would be technically possible if somebody managed to alter your image and mess with your .htaccess files.

                  Could that be a possibility?

                  Have you tried copying the images to a different server to see if it works there?
                  If this is a configuration error or a bug in your Apache installation, re-installing it or upgrading may help.

                  Comment

                  • bytesc
                    New Member
                    • Aug 2008
                    • 7

                    #10
                    The pictures are not uploaded, but downloaded by us.

                    I have uploaded the picture to a different server of mine and it works perfectly. I don't know why i am getting this error only with my older server and why now... this is very strange. Is there a place to check for file assossications in apache?

                    Thanks

                    Comment

                    • pbmods
                      Recognized Expert Expert
                      • Apr 2007
                      • 5821

                      #11
                      How do you display the images? Are you using a PHP proxy page, or do you drop the URL into an img tag?

                      If the only difference between the files that work and the files that don't is that one has numbers in the name and the other has letters (but the extension doesn't change), the only idea that jumps out at me (as Atli suggested, credit where credit's due) is that these images are now triggering some kind of mod_rewrite rule.

                      Comment

                      • pbmods
                        Recognized Expert Expert
                        • Apr 2007
                        • 5821

                        #12
                        I'm going to go ahead and move this thread to the Apache forum and see what else we can come up with.

                        Comment

                        • bytesc
                          New Member
                          • Aug 2008
                          • 7

                          #13
                          I understand that a mod rewrite might be the issue, but I have set none and how would I go about tackling this issue?

                          Thanks,

                          Comment

                          • Atli
                            Recognized Expert Expert
                            • Nov 2006
                            • 5062

                            #14
                            Search for .htaccess files in your file-structure, all the way from the web-root to the directory that contains the image.
                            A .htaccess file can define any number of things that could be causing problems.

                            You should also look through the httpd.conf file. See if you can find anything relating to images.
                            Not sure exactly where redhat puts that file, but a good place to start looking is /etc/apache2

                            Comment

                            Working...