html - Php Image compression and crop does not work for above 3mb jpeg -


i want people upload images page, compress & crop them. given below php code image compression , compress jpeg , download compressed version. works fine upto 3mb(4567*2755) not files above it.

edit:

the message appears in server error log is

[04-jun-2015 08:10:07 europe/paris] php warning: post content-length of 4213306 bytes exceeds limit of 3145728 bytes in unknown on line 0

please :-(

<?php  $name = '';  $type = '';  $size = '';  $error = ''; function compress_image($source_url, $destination_url, $quality)  {      $info = getimagesize($source_url);  if ($info['mime'] == 'image/jpeg')      $image = imagecreatefromjpeg($source_url);  elseif ($info['mime'] == 'image/gif')      $image = imagecreatefromgif($source_url);  elseif ($info['mime'] == 'image/png')      $image = imagecreatefrompng($source_url);      imagejpeg($image, $destination_url, $quality);      return $destination_url;  }   if ($_post)  {  if ($_files["file"]["error"] > 0)  { $error = $_files["file"]["error"];  }  else if (($_files["file"]["type"] == "image/gif") || ($_files["file"]["type"] == "image/jpeg") || ($_files["file"]["type"] == "image/png") || ($_files["file"]["type"] == "image/pjpeg"))  { $url = 'destinationx.jpg';  $filename = compress_image($_files["file"]["tmp_name"], $url, 40);  $buffer = file_get_contents($url); /* force download dialog... */  header("content-type: application/force-download");  header("content-type: application/octet-stream");  header("content-type: application/download"); /* don't allow caching... */ header("cache-control: must-revalidate, post-check=0, pre-check=0"); /* set data type, size , filename */  header("content-type: application/octet-stream");  header("content-transfer-encoding: binary");  header("content-length: " . strlen($buffer));  header("content-disposition: attachment; filename=$url"); /* send our file... */  echo $buffer; } else { $error = "uploaded image should jpg or gif or png"; } } ?>  <html>      <head>          <title>php code compress image</title>      </head>  <body>  <div class="message">      <?php if($_post){ if ($error) { ?>      <label class="error"><?php echo $error; ?></label>      <?php } } ?>  </div>       <fieldset class="well"> <legend>upload image:</legend>  <form action="" name="myform" id="myform" method="post" enctype="multipart/form-data">      <ul>      <li>          <label>upload:</label>          <input type="file" name="file" id="file"/>      </li>          <li>              <input type="submit" name="submit" id="submit" class="submit btn-success"/>          </li>      </ul>  </form>  </fieldset>  </body>  </html> 

your php configuration limiting size of post data 3mb. load larger file need change couple of items in php.ini. can determine location of php.ini php_ini_loaded_file() - see this answer

post_max_size sets maximum size of post. refers all data in post - uploaded file(s) , form variables. need raised 5mb (larger if want handle bigger files)

you'll need set upload_max_filesize larger, smaller post_max_size. again, determine size of files you're need , set accordingly.

these values set in system-wide php.ini file. configurable through .htaccess or php.ini file in application directory; others can set programmatically ini_set(). references have linked tell can set different parameters. reference configuration mode settings here

note hosting companies limit can on cheap (or free) hosting packages. might not able change if you're on free package. there's no work around: better host, , pay if necessary.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -