PHP image upload grey lines
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开发者_Go百科 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
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.
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....
精彩评论