php image upload problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zester
    Confirmed User
    • Jul 2003
    • 5344

    #1

    php image upload problem

    i'm building a tgp script, i have a problem with the thumbnails, they come out distorted.

    here is the code:
    PHP Code:
    if(!eregi("(.jpeg|.jpg)", $_FILES['imagefile']['name']))
    {
        echo "please upload only files in jpg format";
        die;
    }
    if($_FILES['imagefile']['type'] != "image/jpeg" && $_FILES['imagefile']['type'] != "image/pjpeg")
    {
        echo "please upload only files in jpg format";
        die;
    }
    
    $upload_path='/virtual/danny/images/myimage.jpg';
    copy ($_FILES['imagefile']['tmp_name'], $upload_path) or die ("An Error has occured: the thumbnail could not be uploaded to the server"); 
    
    i'm missing something here. what is it?
    * Mainstream ? $65 per sale
    * new male contraception
  • Barefootsies
    Choice is an Illusion
    • Feb 2005
    • 42635

    #2
    Could be something in the PHP library??

    Should You Email Your Members?

    Link1 | Link2 | Link3

    Enough Said.

    "Would you rather live like a king for a year or like a prince forever?"

    Comment

    • Zester
      Confirmed User
      • Jul 2003
      • 5344

      #3
      Originally posted by Barefootsies
      Could be something in the PHP library??


      what could it be in the PHP library?
      * Mainstream ? $65 per sale
      * new male contraception

      Comment

      • Zester
        Confirmed User
        • Jul 2003
        • 5344

        #4
        any ideas?
        * Mainstream ? $65 per sale
        * new male contraception

        Comment

        • mistress69
          Confirmed User
          • Feb 2005
          • 2804

          #5
          bump for ya

          Comment

          • StuartD
            Sofa King Band
            • Jul 2002
            • 29903

            #6
            is the directory you're copying to chmod to 777?
            Does the form have the proper encode type?
            This is me on facebook
            This is me on twitter

            Comment

            • BastarD
              Confirmed User
              • Apr 2004
              • 6341

              #7
              You should check out PHP freaks forums, I'm sure guys there will help ya

              Comment

              • rickholio
                Confirmed User
                • Jan 2004
                • 1914

                #8
                Suggestion: Copy the file with a .phps extension and put it someone where people can click a link to see it. GFY's 'hahahaha' filter makes it really difficult to understand what you're trying to do.

                FWIW - Filtering based on filename isn't as reliable as GetImageSize() to determine if a file is really a jpg or not.
                Last edited by rickholio; 03-08-2005, 12:04 PM.
                ~

                Comment

                • Zester
                  Confirmed User
                  • Jul 2003
                  • 5344

                  #9
                  Originally posted by NichePay - StuartD
                  is the directory you're copying to chmod to 777?
                  yes

                  Originally posted by NichePay - StuartD
                  Does the form have the proper encode type?
                  do you mean this: enctype="multipart/form-data" in the form tag?
                  Last edited by Zester; 03-08-2005, 12:05 PM.
                  * Mainstream ? $65 per sale
                  * new male contraception

                  Comment

                  • Zester
                    Confirmed User
                    • Jul 2003
                    • 5344

                    #10
                    Originally posted by rickholio
                    Suggestion: Copy the file with a .phps extension and put it someone where people can click a link to see it. GFY's 'hahahaha' filter makes it really difficult to understand what you're trying to do.

                    FWIW - Filtering based on filename isn't as reliable as GetImageSize() to determine if a file is really a jpg or not.
                    http://www.geocities.com/dianna_zelda/upload.html
                    * Mainstream ? $65 per sale
                    * new male contraception

                    Comment

                    • rickholio
                      Confirmed User
                      • Jan 2004
                      • 1914

                      #11
                      That snippit of code should work fine, aside from what I said about getimagesize(), and presuming that permissions are set up correctly. In what way are the thumbnails distorted? And are you creating the thumbnails via PHP from full size images, or are you uploading them?
                      ~

                      Comment

                      • Zester
                        Confirmed User
                        • Jul 2003
                        • 5344

                        #12
                        Originally posted by rickholio
                        That snippit of code should work fine, aside from what I said about getimagesize(), and presuming that permissions are set up correctly. In what way are the thumbnails distorted? And are you creating the thumbnails via PHP from full size images, or are you uploading them?
                        they come up distorted as a blur of colors - completely corrupted.
                        I'm just using the above script, not resizing or anything.
                        just uploading.
                        after upload, I try to look at the image via browser as:
                        http://mydomain.com/myimage.jpg and there it is. distorted.

                        I already emailed my host (revsharehosting.com) about this, but if I could only tell him what he can do to fix this, because if doesn't - I don't and i'm fucked.
                        Last edited by Zester; 03-08-2005, 01:33 PM.
                        * Mainstream ? $65 per sale
                        * new male contraception

                        Comment

                        • Zester
                          Confirmed User
                          • Jul 2003
                          • 5344

                          #13
                          here is the form by the way:
                          [HTML]
                          <form name="form1" method=hahahahahaha action="" enctype="multipart/form-data">
                          <input type="file" name="imagefile">
                          <input type="submit" name="Submit" value="Submit">
                          </form>
                          [/HTML]
                          * Mainstream ? $65 per sale
                          * new male contraception

                          Comment

                          • rickholio
                            Confirmed User
                            • Jan 2004
                            • 1914

                            #14
                            Can you post links to the before and after? There definately sounds like some kind of corruption is going on, I'm curious to see what's happening to the image itself.
                            ~

                            Comment

                            • Zester
                              Confirmed User
                              • Jul 2003
                              • 5344

                              #15
                              the response from the host is that GD is needed for this
                              what do you guys think about that?
                              * Mainstream ? $65 per sale
                              * new male contraception

                              Comment

                              • Zester
                                Confirmed User
                                • Jul 2003
                                • 5344

                                #16
                                i think this is something to do with the type of the file (Binary / Ascii)
                                how do I set those on upload or move ?
                                * Mainstream ? $65 per sale
                                * new male contraception

                                Comment

                                • rickholio
                                  Confirmed User
                                  • Jan 2004
                                  • 1914

                                  #17
                                  GD isn't required for file uploads, only for times when you want to do things like GetImageSize(). If you're purely shuffling bytes around, you don't need it.

                                  Binary/Ascii only should apply when dealing with FTP transfers. Web-based uploads don't have the same caveats (or at least they shouldn't!), but that's part of the reason why I wanted to see a before image and an after image, so I could see if there was some sort of corruption going on during the upload phase.
                                  ~

                                  Comment

                                  • Zester
                                    Confirmed User
                                    • Jul 2003
                                    • 5344

                                    #18
                                    Originally posted by rickholio
                                    GD isn't required for file uploads, only for times when you want to do things like GetImageSize(). If you're purely shuffling bytes around, you don't need it.

                                    Binary/Ascii only should apply when dealing with FTP transfers. Web-based uploads don't have the same caveats (or at least they shouldn't!), but that's part of the reason why I wanted to see a before image and an after image, so I could see if there was some sort of corruption going on during the upload phase.
                                    i DO use getimagesize() but that's seems to get the vars ok - please look at the code i posted, i posted a link

                                    here is a "before": (used upload via php)
                                    http://footfetishgallery.net/gallery/thumbnails/04.jpg

                                    here is an "after": (used FTP)
                                    http://footfetishgallery.net/gallery/thumbnails/04b.jpg
                                    Last edited by Zester; 03-09-2005, 09:30 AM.
                                    * Mainstream ? $65 per sale
                                    * new male contraception

                                    Comment

                                    • Zester
                                      Confirmed User
                                      • Jul 2003
                                      • 5344

                                      #19
                                      just added "sleep(20);" before the "copy" command thinking the image might be copied before it has been fully uploaded or something - I got the same result.

                                      maybe i did'nt put it in the right place
                                      * Mainstream ? $65 per sale
                                      * new male contraception

                                      Comment

                                      • rickholio
                                        Confirmed User
                                        • Jan 2004
                                        • 1914

                                        #20
                                        Originally posted by Zester
                                        i DO use getimagesize() but that's seems to get the vars ok - please look at the code i posted, i posted a link

                                        here is a "before": (used upload via php)
                                        http://footfetishgallery.net/gallery/thumbnails/04.jpg

                                        here is an "after": (used FTP)
                                        http://footfetishgallery.net/gallery/thumbnails/04b.jpg
                                        Can't grab em... looks like you have some variety of hotlink protection on. Can you make a page that links to those images?

                                        AFAIK, the php page doesn't even run until the entire request has completed, and file uploads are part of the request... so no sleep() would be necessary.
                                        ~

                                        Comment

                                        • Zester
                                          Confirmed User
                                          • Jul 2003
                                          • 5344

                                          #21
                                          Originally posted by rickholio
                                          Can't grab em... looks like you have some variety of hotlink protection on. Can you make a page that links to those images?

                                          AFAIK, the php page doesn't even run until the entire request has completed, and file uploads are part of the request... so no sleep() would be necessary.
                                          try this:
                                          http://footfetishgallery.net/gallery/temp.html




                                          i'm really out of ideas about this
                                          * Mainstream ? $65 per sale
                                          * new male contraception

                                          Comment

                                          • rickholio
                                            Confirmed User
                                            • Jan 2004
                                            • 1914

                                            #22
                                            Aha, I think I have it.

                                            I did a 'strings' on your 04b.gif file and found the following:

                                            -----------------------------7d51181aaf4
                                            Content-Disposition: form-data; name="imagefile"; filename="C:\backup\guitarstuff\project\tgp\xf\1\0 4.jpg"
                                            Content-Type: image/pjpeg

                                            It would appear that you're saving the entire raw response string, and not purely the image itself. It maybe the way the file gets handled in the code?

                                            Here's what I've used in the past:

                                            Code:
                                                  if(is_uploaded_file($_FILES[img][tmp_name])) {
                                                     $szarr = getimagesize($_FILES[img][tmp_name]);
                                                     if($szarr[2]=IMAGETYPE_JPEG) move_uploaded_file($_FILES[img][tmp_name], $file_target);
                                                  }
                                            The only other alternative is that your webserver is not correctly separating out the different form submission elements, in which case you have bigger problems.

                                            HTH.
                                            ~

                                            Comment

                                            • calmlikeabomb
                                              Confirmed User
                                              • May 2004
                                              • 1323

                                              #23
                                              Hi,

                                              This might be of help to you, but I am not sure. It's something I use to upload and move a file to a directory on my server and the GD library also makes a thumbnail version of the image and uploads it to the same directory, but adds a prefix the image name.

                                              I put it in a .txt for you:

                                              http://www.penis-enlargement-product.us/misc/zester.txt
                                              subarus.

                                              Comment

                                              • rickholio
                                                Confirmed User
                                                • Jan 2004
                                                • 1914

                                                #24
                                                Originally posted by calmlikeabomb
                                                Hi,

                                                This might be of help to you, but I am not sure. It's something I use to upload and move a file to a directory on my server and the GD library also makes a thumbnail version of the image and uploads it to the same directory, but adds a prefix the image name.

                                                I put it in a .txt for you:

                                                http://www.penis-enlargement-product.us/misc/zester.txt
                                                This is very similar to what I do, although I use PNG for very small thumbnails instead of jpeg (I find they retain detail better at the small sizes). I'm not entirely convinced that his server or browser are working as advertised though. The uploaded image is, for some reason, substantially larger than the source... additionally, it appears as though there's about 2k of data at the head of the image, followed by the request header and another copy of the full image. Something Is Just Not Right(tm), and I've got a suspicion that it's something amiss in the actual upload process, not the post-upload processing.
                                                ~

                                                Comment

                                                • Zester
                                                  Confirmed User
                                                  • Jul 2003
                                                  • 5344

                                                  #25
                                                  Originally posted by rickholio
                                                  Aha, I think I have it.

                                                  I did a 'strings' on your 04b.gif file and found the following:

                                                  -----------------------------7d51181aaf4
                                                  Content-Disposition: form-data; name="imagefile"; filename="C:\backup\guitarstuff\project\tgp\xf\1\0 4.jpg"
                                                  Content-Type: image/pjpeg

                                                  It would appear that you're saving the entire raw response string, and not purely the image itself. It maybe the way the file gets handled in the code?

                                                  Here's what I've used in the past:

                                                  Code:
                                                        if(is_uploaded_file($_FILES[img][tmp_name])) {
                                                           $szarr = getimagesize($_FILES[img][tmp_name]);
                                                           if($szarr[2]=IMAGETYPE_JPEG) move_uploaded_file($_FILES[img][tmp_name], $file_target);
                                                        }
                                                  The only other alternative is that your webserver is not correctly separating out the different form submission elements, in which case you have bigger problems.

                                                  HTH.

                                                  tried the code you posted here and got the same result mate
                                                  * Mainstream ? $65 per sale
                                                  * new male contraception

                                                  Comment

                                                  • rickholio
                                                    Confirmed User
                                                    • Jan 2004
                                                    • 1914

                                                    #26
                                                    It's a strange bug... the php code is correct, the form element looks right, and the picture is presumably getting to the right place, the problem is that it's getting messed in the upload.

                                                    Have you tried uploading it using a different browser? If it works via a new browser, then it's your old one that's breaking... if it's still buggered, then somehow your server is broken. Having that multipart header embedded in the upload stream is very odd indeed. I'm leaning towards a broken server at this point.
                                                    ~

                                                    Comment

                                                    • Zester
                                                      Confirmed User
                                                      • Jul 2003
                                                      • 5344

                                                      #27
                                                      Originally posted by rickholio
                                                      It's a strange bug... the php code is correct, the form element looks right, and the picture is presumably getting to the right place, the problem is that it's getting messed in the upload.

                                                      Have you tried uploading it using a different browser? If it works via a new browser, then it's your old one that's breaking... if it's still buggered, then somehow your server is broken. Having that multipart header embedded in the upload stream is very odd indeed. I'm leaning towards a broken server at this point.

                                                      tried it with other browsers
                                                      same thing

                                                      any idea how the hell my host can handle this? what to tell him?
                                                      * Mainstream ? $65 per sale
                                                      * new male contraception

                                                      Comment

                                                      • woj
                                                        <&(©¿©)&>
                                                        • Jul 2002
                                                        • 47882

                                                        #28
                                                        Is your host using recent version of php and apache?
                                                        Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
                                                        Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
                                                        Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager

                                                        Comment

                                                        • Zester
                                                          Confirmed User
                                                          • Jul 2003
                                                          • 5344

                                                          #29
                                                          Originally posted by woj
                                                          Is your host using recent version of php and apache?
                                                          do you think it can be something to do with the PHP or Apache version?
                                                          * Mainstream ? $65 per sale
                                                          * new male contraception

                                                          Comment

                                                          • rickholio
                                                            Confirmed User
                                                            • Jan 2004
                                                            • 1914

                                                            #30
                                                            Originally posted by Zester
                                                            tried it with other browsers
                                                            same thing

                                                            any idea how the hell my host can handle this? what to tell him?
                                                            Lay it out like this:

                                                            - Your images are being corrupted on upload.

                                                            - You've checked, changed, and confirmed that the code used to process uploads is correct and verified by third parties

                                                            - The image itself is being corrupted in the upload process. The uploaded image contains part of the headers from the submission, plus extra crap that doesn't belong. Show them the before and after, and point out that the uploaded image ends up LARGER than the original image.

                                                            - Make sure they know you've tried uploading with different browser types, removing a broken browser as being the reason for the failure

                                                            - Try uploading other images to see if it happens regardless of the source, which will remove the possibility of a broken graphic as the cause

                                                            - By the process of elimination (not browser, not code, not image) the only other option would be the way the server handles it.
                                                            ~

                                                            Comment

                                                            Working...