Home > Backend Development > PHP Tutorial > PHP implements image uploading and uses ImageMagick to generate thumbnails, _PHP tutorial

PHP implements image uploading and uses ImageMagick to generate thumbnails, _PHP tutorial

WBOY
Release: 2016-07-12 08:57:08
Original
737 people have browsed it

php implements image uploading and uses ImageMagick to generate thumbnails,

Using ImageMagick, you can create thumbnails easily and faster, much easier than using PHP.

<&#63;php
// Location to upload main image:
$mainDir = $_SERVER['DOCUMENT_ROOT'].'/images/l/';
// Location to create the thumb image:
$smalDir = $_SERVER['DOCUMENT_ROOT'].'/images/s/';
// Command to use:
$command = '/usr/bin/convert';
// Thumbnail width:
$size = 210;
// Make sure we have an image:
if(isset($_POST['submit'])){
if(getimagesize($_FILES['photo']['tmp_name'])){
$name = $_FILES['photo']['name'];
$uploadfile = $mainDir . $name;
move_uploaded_file($_FILES['photo']['tmp_name'], $uploadfile);
$lrgImg = $mainDir . $name;
$smlImg = $smalDir . $name;
$imageMagick = $command . " '". $lrgImg . "' -resize '$size' '" . $smlImg . "'";
shell_exec($imageMagick);
}
header("Location: /test.php");
exit;
}else{
&#63;>
<form action=" <&#63;php echo $_SERVER['PHP_SELF']; &#63;> " method="post" enctype="multipart/form-data">
<p><input type="file" name="photo" /></p>
<p><input type="submit" value="Upload!" name="submit" /></p>
</form>
<&#63;php
foreach(glob($smalDir.'*') as $img){
echo ' <img src="'.str_replace($_SERVER['DOCUMENT_ROOT'], '',$img).'" /> ';
}
}
&#63;>
Copy after login

I hope this article will help you learn PHP programming.

Articles you may be interested in:

  • PHP image upload class with image display
  • Simple PHP image upload program
  • php image upload class code
  • Super easy to use PHP image upload class (random name, thumbnail, watermark)
  • PHP image upload code
  • PHPThumb PHP image thumbnail gallery
  • Share the image upload function implemented by thinkphp
  • Thumbnail generation class implemented by php that supports imagemagick and gd library processing
  • Detailed explanation of multiple file and image upload examples in php

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1110083.htmlTechArticlephp implements image uploading and uses ImageMagick to generate thumbnails. Using ImageMagick, you can create thumbnails easily and faster , much easier than using PHP. php// Location to upload...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template