Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

image upload (blurred from one PC/good from the other)

Status
Not open for further replies.

lambi2001

Programmer
Feb 2, 2005
18
DE
Hello, I have a problem with an image upload script.

I am using php to upload an jpg image to a web server. On the server the image is not touched by any kind of manipulating script.
I use move_uploaded_file() and copy() to change the name of the image.

Now when I upload an image from my PC everything is fine.

When somebody uploads the image from a different PC the image is getting blurred.

We are both using windows.

The changes in the images are considerably and I dont know why this happens.

Any help is highly appreciated
 
I assume you are trying to upload the same image from both pc's? have you tried uploading other files to see whether they become similarly corrupt?

are you viewing the resultant image in a file viewer on the server or trying to re-download the image to a browser?

if the latter, have you tried downloading the image as a file to the client pc and then opening in a file viewer? It could be that the client browser is set to view low quality images or is using a program like onspeed etc.

In short this is very unlikely to be a php issue (as an image is just a data stream) and more likely to be a configuration issue. One other thing to try is to flush the browser's cache just in case you are not really downloading an image but just a cached version of it. also you could try another browser as a double-check.
 
Thanks for the reply,

We tried it with several images with the same problem.
From my machine it works fine, from the other (which has a different location and a different ISP) the images get blurred.

Also changing the browser did not help, so I guess it will be someting like onspeed. I will check,

Thanks
 
Is it the same image that you are uploading from both computers? You probably know this already, but just in case : If the images are large, and you are opening them directly into a browser rather than linking to them from an img tag in a web page, then most browsers re-size large images to fit in the browser window by default. The resized images are often fuzzy.

Just a thought.

 
Its the same image and there is no resizing.
Looking at it through the img tag or directly makes no difference.

thanks
 
what does the image look like in a standard JPG viewer e.g. double click on it in windows explorer (asuming windows) or download a viewer from a site such as Can you do this and report back, it would be interesting to see if the browser is acting up or the image itself is being couruped.
 
Hi ingresman,

it is the image itself that is being corrupted.
They have different sizes.
I look at them through imageready for example or the windows preview.
The bad one is nearly twice as big as the good one.

I still didnt hear back from the other computer on if they are using an ISP that somehow compresses images, but until now that seems the most plausible explanation.

Although it is strange the the bad image has a bigger size, hm?
 
can you check the server copy just to make sure that it is not corrupt.

have you definitely flushed the browser's cache? (i guess you have done the equivalent if you have tested a different browser).

also perhaps you could post the uri here so we could take a look and feedback to you if we receive the same behaviour.

 
it's larger, i wonder if the encoding is making it an unicode file.
Could you create a very small jpg 2x2 pixels and send in hex dump of it, a hex dump on the good machine and a hex dump on the bad machine, be interesting to see whats physicaly going on
 
I will try to do that, but must admit that I am not really sure about the hex dump.
I have a trial version of ultra edit and can look at the images in hex mode.
So you mean to save this and to have a look at it?
 
So I hope that this is what was meant:
I created a 2*2 pixel jpg file on my (good) machine and uploaded it.
Then I send it to the other machine and they uploaded it.

I downloaded both images from the server via ftp

The bad machine blew the image up to 400*400 px so I will only include the first part of the hex code.

This is the good one:
00000000h: FF D8 FF E0 00 10 4A 46 49 46 00 01 02 00 00 64 ; ÿØÿà..JFIF.....d
00000010h: 00 64 00 00 FF EC 00 11 44 75 63 6B 79 00 01 00 ; .d..ÿì..Ducky...
00000020h: 04 00 00 00 64 00 00 FF EE 00 0E 41 64 6F 62 65 ; ....d..ÿî..Adobe
00000030h: 00 64 C0 00 00 00 01 FF DB 00 84 00 01 01 01 01 ; .dÀ....ÿÛ.„.....
00000040h: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ; ................
00000050h: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ; ................
00000060h: 01 01 01 01 01 01 01 02 02 02 02 02 02 02 02 02 ; ................
00000070h: 02 02 03 03 03 03 03 03 03 03 03 03 01 01 01 01 ; ................
00000080h: 01 01 01 02 01 01 02 02 02 01 02 02 03 03 03 03 ; ................
00000090h: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ; ................
000000a0h: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ; ................
000000b0h: 03 03 03 03 03 03 03 03 03 03 03 03 03 FF C0 00 ; .............ÿÀ.
000000c0h: 11 08 00 02 00 02 03 01 11 00 02 11 01 03 11 01 ; ................
000000d0h: FF C4 00 56 00 01 00 00 00 00 00 00 00 00 00 00 ; ÿÄ.V............
000000e0h: 00 00 00 00 00 08 01 01 01 00 00 00 00 00 00 00 ; ................
000000f0h: 00 00 00 00 00 00 00 05 08 10 00 02 03 00 00 00 ; ................
00000100h: 00 00 00 00 00 00 00 00 00 00 00 F0 87 38 98 11 ; ...........ð‡8˜.
00000110h: 00 02 01 05 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000120h: 00 F0 84 36 86 96 37 97 FF DA 00 0C 03 01 00 02 ; .ð„6†–7—ÿÚ......
00000130h: 11 03 11 00 3F 00 38 6C 8B 90 C8 25 11 CA B5 53 ; ....?.8l‹?È%.ʵS
00000140h: 76 8D 64 D5 33 24 FF D9 ; v?dÕ3$ÿÙ


And her comes the first lines of the bad one:


00000000h: FF D8 FF E0 00 10 4A 46 49 46 00 01 01 00 00 01 ; ÿØÿà..JFIF......
00000010h: 00 01 00 00 FF FE 00 3C 43 52 45 41 54 4F 52 3A ; ....ÿþ.<CREATOR:
00000020h: 20 67 64 2D 6A 70 65 67 20 76 31 2E 30 20 28 75 ; gd-jpeg v1.0 (u
00000030h: 73 69 6E 67 20 49 4A 47 20 4A 50 45 47 20 76 36 ; sing IJG JPEG v6
00000040h: 32 29 2C 20 71 75 61 6C 69 74 79 20 3D 20 31 30 ; 2), quality = 10
00000050h: 30 0A FF DB 00 43 00 01 01 01 01 01 01 01 01 01 ; 0.ÿÛ.C..........
00000060h: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ; ................
00000070h: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ; ................
00000080h: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ; ................
00000090h: 01 01 01 01 01 01 01 FF DB 00 43 01 01 01 01 01 ; .......ÿÛ.C.....
000000a0h: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ; ................
000000b0h: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ; ................
000000c0h: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ; ................
000000d0h: 01 01 01 01 01 01 01 01 01 01 01 01 FF C0 00 11 ; ............ÿÀ..
000000e0h: 08 01 90 01 90 03 01 22 00 02 11 01 03 11 01 FF ; ..?.?..".......ÿ
000000f0h: C4 00 1F 00 00 01 05 01 01 01 01 01 01 00 00 00 ; Ä...............
00000100h: 00 00 00 00 00 01 02 03 04 05 06 07 08 09 0A 0B ; ................
00000110h: FF C4 00 B5 10 00 02 01 03 03 02 04 03 05 05 04 ; ÿÄ.µ............
00000120h: 04 00 00 01 7D 01 02 03 00 04 11 05 12 21 31 41 ; ....}........!1A
00000130h: 06 13 51 61 07 22 71 14 32 81 91 A1 08 23 42 B1 ; ..Qa."q.2?‘¡.#B±
00000140h: C1 15 52 D1 F0 24 33 62 72 82 09 0A 16 17 18 19 ; Á.RÑð$3br‚......
00000150h: 1A 25 26 27 28 29 2A 34 35 36 37 38 39 3A 43 44 ; .%&'()*456789:CD
00000160h: 45 46 47 48 49 4A 53 54 55 56 57 58 59 5A 63 64 ; EFGHIJSTUVWXYZcd
00000170h: 65 66 67 68 69 6A 73 74 75 76 77 78 79 7A 83 84 ; efghijstuvwxyzƒ„
00000180h: 85 86 87 88 89 8A 92 93 94 95 96 97 98 99 9A A2 ; …†‡ˆ‰Š’“”•–—˜™š¢
00000190h: A3 A4 A5 A6 A7 A8 A9 AA B2 B3 B4 B5 B6 B7 B8 B9 ; £¤¥¦§¨©ª²³´µ¶·¸¹
000001a0h: BA C2 C3 C4 C5 C6 C7 C8 C9 CA D2 D3 D4 D5 D6 D7 ; ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×
000001b0h: D8 D9 DA E1 E2 E3 E4 E5 E6 E7 E8 E9 EA F1 F2 F3 ; ØÙÚáâãäåæçèéêñòó
000001c0h: F4 F5 F6 F7 F8 F9 FA FF C4 00 1F 01 00 03 01 01 ; ôõö÷øùúÿÄ.......
000001d0h: 01 01 01 01 01 01 01 00 00 00 00 00 00 01 02 03 ; ................
000001e0h: 04 05 06 07 08 09 0A 0B FF C4 00 B5 11 00 02 01 ; ........ÿÄ.µ....
000001f0h: 02 04 04 03 04 07 05 04 04 00 01 02 77 00 01 02 ; ............w...
00000200h: 03 11 04 05 21 31 06 12 41 51 07 61 71 13 22 32 ; ....!1..AQ.aq."2
00000210h: 81 08 14 42 91 A1 B1 C1 09 23 33 52 F0 15 62 72 ; ?..B‘¡±Á.#3Rð.br


Gernerally, looking at the hex goes a little bit over my head, but I would be happy if somebody could explain what happend here.
 
yes, a small image should not occupy much space, you could use the cmd prompt command debug. I created a 2x2 jpg image and it is 631 bytes so is easily handled. Debug can be a bit tricky to sometimes.
just as a side thought have you tried a gif or png image at all?
 
isn't there a jpg virus that does something like this (perrun or something like that from memory)
 
It is called perrun
It would seem likely that code is doing the change as the dump shows that is has been through a gd call (look just after the JFIF text.

Accrrding to the info it plays with jpg and txt files so if you could try a gif that would be good and we should be able to prove or disproove he virus theory (which is looking good to be honest), could you by any chance try a 3rd machine
 
An additional thought, what does the image look like localy on the bad machine ?
 
So we uploaded gifs now. Same thing a small 2*2 px gif.

The thing is, that gifs (and pngs) are being processed by the gd library and converted to jpgs. Does this matter?

Both hex dumps are identical, which is why I am not puttting them here (unless somebody wants to see them)

So does this suggest, that the other (bad) machine has a virus?
 
So, let me get this straight you put the gif through a GD call to convert it. Does this happen with a .jpg as well ?.
I thought your code just uploaded and copied to change the name.
Can you give a text decription of what actualy happens, or if the code is short enough please post it.

Which hex dumps are identical now - and are they corrupted ?
 
Sorry for the confusion:

jpgs are only uploaded and renamed
gifs and pngs are uploaded and converted to jpgs

her is some part of the code:

// this is part of a function that is called when the file is not empty

$result = move_uploaded_file($temp_name, $uploaddir.$realname);

$name = explode(".", $realname);

$extension = $name[1];
$extension = strtolower($extension);
$picturename = $name[0];

if ($extension == 'jpg') {

$res1 = copy($uploaddir.$realname, $picturedir.$finalname);

if (!$res1) {
// display error msg
}

@unlink($uploaddir.$realname);



} else if ($extension == 'gif') {

$im = imagecreatefromgif($uploaddir.$realname);

if (!$im) { /* See if it failed */
$im = imagecreate (150, 30); /* Create a blank image */
$bgc = imagecolorallocate ($im, 255, 255, 255);
$tc = imagecolorallocate ($im, 0, 0, 0);
imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring ($im, 1, 5, 5, "Error loading $realname",$tc);
echo($im);
exit;
}

imagejpeg($im, $picturedir.$picturename.".jpg");

imagedestroy($im);

@unlink($uploaddir.$realname);




} else if // her come the same for pngs


so we are checking for the extensions, if its a jpg we move and rename it, if its is a gif or png we make it a jpg and rename it

We tried it with gifs as I said and the two hex dumps of the gifs are identical and not corrupted
 
Ok, I wonder if:
The test for == jpg is failing for some reason , could you put a little echo "at jpg"; just after the If (to confirm it really) and if it is passing the test can you display the filesize at this point
Code:
$filename = 'somefile.txt';
echo $filename . ': ' . filesize($filename) . ' bytes';
We can see if the raw file is ok.
One thing i did notice in the code is you make a variable $picturename but dont use it, you use $finalname instead, also should you have a "/" between the dir and file (assume it is is in $picturedir.
Having said this it does still look like the bad PC is doing something odd. This set of debugs might make it a bit clearer.
If you can run the test on both machines and post the results that will be good. also did you get a chance to see what the file renders like on the bad PC?
 
OK I will have to get back to that as it is getting late at my coordinates and my head is burning a little bit. Must cool it down.

the image on the bad pc looks good if you look at it with a normal viewer, just after the upload if you look at it through the img tag or download it from the server its bad.


Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top