GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   php image upload problem (https://gfy.com/showthread.php?t=441467)

Zester 03-08-2005 10:02 AM

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?

Barefootsies 03-08-2005 10:04 AM

Could be something in the PHP library??

:helpme

Zester 03-08-2005 10:37 AM

Quote:

Originally Posted by Barefootsies
Could be something in the PHP library??

:helpme


what could it be in the PHP library?

Zester 03-08-2005 01:43 PM

any ideas?

mistress69 03-08-2005 01:43 PM

bump for ya

StuartD 03-08-2005 01:45 PM

is the directory you're copying to chmod to 777?
Does the form have the proper encode type?

BastarD 03-08-2005 01:47 PM

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

rickholio 03-08-2005 02:01 PM

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. :2 cents:

Zester 03-08-2005 02:04 PM

Quote:

Originally Posted by NichePay - StuartD
is the directory you're copying to chmod to 777?

yes

Quote:

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?

Zester 03-08-2005 02:17 PM

Quote:

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. :2 cents:

http://www.geocities.com/dianna_zelda/upload.html

rickholio 03-08-2005 02:49 PM

Quote:

Originally Posted by Zester

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?

Zester 03-08-2005 03:31 PM

Quote:

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.

Zester 03-08-2005 03:35 PM

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]

rickholio 03-08-2005 04:33 PM

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.

Zester 03-09-2005 09:04 AM

the response from the host is that GD is needed for this
what do you guys think about that?

Zester 03-09-2005 10:06 AM

i think this is something to do with the type of the file (Binary / Ascii)
how do I set those on upload or move ?

rickholio 03-09-2005 10:48 AM

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.

Zester 03-09-2005 11:27 AM

Quote:

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

Zester 03-09-2005 12:22 PM

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

rickholio 03-09-2005 12:38 PM

Quote:

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.

Zester 03-09-2005 01:04 PM

Quote:

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

rickholio 03-09-2005 03:59 PM

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. :thumbsup

calmlikeabomb 03-09-2005 04:10 PM

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

rickholio 03-09-2005 04:27 PM

Quote:

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.

Zester 03-10-2005 10:14 AM

Quote:

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. :thumbsup


tried the code you posted here and got the same result mate

rickholio 03-10-2005 11:29 AM

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.

Zester 03-10-2005 12:12 PM

Quote:

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?

woj 03-10-2005 12:19 PM

Is your host using recent version of php and apache?

Zester 03-10-2005 02:06 PM

Quote:

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?

rickholio 03-10-2005 04:44 PM

Quote:

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.


All times are GMT -7. The time now is 05:30 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123