PHP imagemagick image upload thumbnail


SUBMITTED BY: Guest

DATE: Oct. 22, 2013, 1 p.m.

FORMAT: PHP

SIZE: 1.4 kB

HITS: 1064

  1. <?php
  2. // Location to upload main image:
  3. $mainDir = $_SERVER['DOCUMENT_ROOT'].'/images/l/';
  4. // Location to create the thumb image:
  5. $smalDir = $_SERVER['DOCUMENT_ROOT'].'/images/s/';
  6. // Command to use:
  7. $command = '/usr/bin/convert';
  8. // Thumbnail width:
  9. $size = 210;
  10. // Make sure we have an image:
  11. if(isset($_POST['submit'])){
  12. if(getimagesize($_FILES['photo']['tmp_name'])){
  13. $name = $_FILES['photo']['name'];
  14. $uploadfile = $mainDir . $name;
  15. move_uploaded_file($_FILES['photo']['tmp_name'], $uploadfile);
  16. $lrgImg = $mainDir . $name;
  17. $smlImg = $smalDir . $name;
  18. $imageMagick = $command . " '". $lrgImg . "' -resize '$size' '" . $smlImg . "'";
  19. shell_exec($imageMagick);
  20. }
  21. header("Location: /test.php");
  22. exit;
  23. }else{
  24. ?>
  25. <form action=" <?php echo $_SERVER['PHP_SELF']; ?> " method="post" enctype="multipart/form-data">
  26. <p><input type="file" name="photo" /></p>
  27. <p><input type="submit" value="Upload!" name="submit" /></p>
  28. </form>
  29. <?php
  30. foreach(glob($smalDir.'*') as $img){
  31. echo ' <img src="'.str_replace($_SERVER['DOCUMENT_ROOT'], '',$img).'" /> ';
  32. }
  33. }
  34. ?>

comments powered by Disqus