title: php png image quality 50%
body: <p>I have a php script I'm using to convert an uploaded image into half it's quality so I can save server space, but it isn't working I'm new to PHP so hopefully someone can help me where I am going wrong.</p>
  
  <pre><code>if(isset($_FILES['t1']['name'])){
      $file = rand(0, 10000000).$_FILES['t1']['name'];
      if (move_uploaded_file($_FILES['t1']['tmp_name'], $file)) {
          if($fp = fopen($file,"rb", 0))
          {
             $picture = fread($fp,filesize($file));
             fclose($fp);
             $img = imagecreatefrompng($file);
             imagepng($img, $file, 6); //6 quality setting
             imagedestroy($img);
             $tag1 = '&lt;img src="'.$file.'" alt="" class="default" /&gt;';
  //unlink($file);
  echo "&lt;script&gt;$(document).ready(function() {var write = $('.item:nth-child(1)').html();localStorage.item1Pantry = write;});&lt;/script&gt;";      
          }
      }
  
  
  }
  </code></pre>