title: PHP image upload grey lines
body: <p>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:</p>
  
  <p><a href="http://5oup.net/sites/default/files/360/5ouppic.jpg" rel="nofollow noreferrer">http://5oup.net/sites/default/files/360/5ouppic.jpg</a></p>
  
  <p>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.</p>
  
  <p>Here is the PHP from my module which handles the upload:</p>
  
  <pre><code>$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);
  </code></pre>
  
  <p>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!</p>
  
  <p>James</p>
  
  <hr>
  
  <p><strong>EDIT - Able to reproduce problem</strong></p>
  
  <p>I have contacted a user and am able to recreate the problem (i.e. it uploads with grey pixels every time) using this jpeg:</p>
  
  <p><a href="http://5oup.net/test/sucon.jpg" rel="nofollow noreferrer">http://5oup.net/test/sucon.jpg</a></p>
  
  <p>This jpeg uploads fine:</p>
  
  <p><a href="http://5oup.net/test/hd.jpg" rel="nofollow noreferrer">http://5oup.net/test/hd.jpg</a></p>
  
  <p>I just can't figure out the difference?! What on earth could be going on?</p>
  
  <p>Thanks</p>