views:

148

answers:

2

Hello!

I have a custom drupal module which saves uploaded files passed from the uploadify jquery plugin. All seemed well but some images are coming up with grey blocks in them. See:

http://5oup.net/sites/default/files/360/5ouppic.jpg

This is a user submitted image and I'm unable to reproduce the problem myself - as I understand it it's a server side problem, but I'm unsure about how to rectify the issue.

Here is the PHP from my module which handles the upload:

$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';

$filename = $_FILES['Filedata']['name'];
$filename = preg_replace("/[^A-Za-z0-9. ]/", '', $filename);
$filename = str_replace(" ", '_', $filename);

$targetFile =  str_replace('//','/',$targetPath) . $filename;       

$name = $filename;

mkdir(str_replace('//','/',$targetPath), 0755, true);
move_uploaded_file($tempFile,$targetFile);

Is the upload 'stalling' somehow? Any ideas about why it would only be on some images and not others? Any help is very gratefully received!

James


EDIT - Able to reproduce problem

I have contacted a user and am able to recreate the problem (i.e. it uploads with grey pixels every time) using this jpeg:

http://5oup.net/test/sucon.jpg

This jpeg uploads fine:

http://5oup.net/test/hd.jpg

I just can't figure out the difference?! What on earth could be going on?

Thanks

A: 

Hi James,

I think that $_SERVER['DOCUMENT_ROOT'] will give the document path of the site without slash('/') at the end.

Please replace the second line of your above code with below line,

$targetPath = $_SERVER['DOCUMENT_ROOT'] .'/'. $_REQUEST['folder'] . '/';

Hope this will help for you....

Avinash
+1  A: 

While it could of course have been a transmission error that damaged a small part of the JPG image, if this was a single incident, I would look on the user's side first. It's much, much more likely something went wrong when they resized the image before uploading. Ask them whether they resized the image immediately before uploading, and what the resized file looks like. Have them E-Mail you everything.

Maybe you want to upload the original, undamaged file as well, somebody here may be able to tell more by taking a look into it.

I would first check whether it can be reproduced on the user's side from a intact image (have them E-Mail it to you), and from a different image.


Edit (ran out of space in the comment)

Very, very strange. From what little I know about the JPG format, this could be the typical behaviour when the transmission gets mangled during only a few bytes: A number of blocks could be affected and lead to this. What it could be, I can't say - could be anything from hard disk problems (unlikely) to some firewall filtering out data. The first step would definitely be obtaining the original images and seeing whether the problem can be reproduced. My bet is it can't. Then a disk check is in order, and as much replacing and changing and testing as you can (move temporary directory / updating the server software maybe).

If nothing helps, as a last resort, you may want to set up a mirror copy of the site on another server, and do some automated uploading there to see whether it happens again. Selenium IDE could be a help for that.

By the way, you may want to post-process users' images to protect their privacy. The EXIF data reveal quite a lot, check out this for example or this.

Pekka
Thanks for the suggestion, I'll get in touch with them and see if I can reproduce the problem.
James Chambers
I have gotten in touch with the user, however I should point out this has happened for quite a few images across the site, I would say between 5-10% of uploaded images.
James Chambers
Oh, okay then, then something is probably up on the server end. There is definitely *no* post-processing / resizing of any kind involved at all? Only the raw upload of original images?
Pekka
No, just the code in my question then some database stuff. It's a puzzler all right!
James Chambers
See my edited answer, I ran out of space here.
Pekka
Thanks very much for your help, I will work through your suggestions and post back with hopefully good news. Also thanks for the heads-up on the EXIF data, worryingly revealing!
James Chambers