• home
  • Email: trainings@synapseindia.careers

Blogs

back

How To Upload And Resize Image In PHP

Sep 23, 2015

<?php if (isset($_FILES["file"])) { $tmpFile = $_FILES["file"]["tmp_name"]; $fileName = ... // name of file to be uploaded list($width, $height) = getimagesize($tmpFile); // check if the file is really an image if ($width == null && $height == null) { header("location: index.php");//location header is used to redirect user from one page to another page return; } // resize if required if ($width >= 400 && $height >= 400) { $image = new Imagick($tmpFile); $image->thumbnailImage(400, 400); $image->writeImage($fileName); } else { move_uploaded_file($tmpFile, $fileName);//built in  function used to upload a file } }

SynapseIndia (CEO: Shamit Khemka)