Requires: PHP w/ GD Library Extension.
Generating thumbnails couldn't be easier. Download the file on this page and test it out.
Simply include the following PHP into the top part of the page, this processes the form and calls the external class and loads it as an object. The following can be produced, all dimensions can be altered for each file.
![]()
A very basic installation would be as follows:
<?
require_once 'thumbnail.class.php';
$thumbnail = new thumbnail;if (!empty($_REQUEST['submit']))
{
$tmp = $_FILES['uploaded_file']['tmp_name'];
$org = $_FILES['uploaded_file']['name'];if ($tmp)
{
$directory = 'uploads'; // Upload files to here.
$prefix = 'uploaded_'; // Filename prefixes// Upload all image files
$lrgImage = $thumbnail->generate($tmp, $org, $directory, $prefix.'lrg', 300); // large file
$medImage = $thumbnail->generate($tmp, $org, $directory, $prefix.'med', 200); // medium file
$smlImage = $thumbnail->generate($tmp, $org, $directory, $prefix.'sml', 100); // small fileif ($smlImage && $medImage && $lrgImage) // If all files are ok
{
$info = '
<fieldset>
<legend>Files uploaded successfully</legend>
<img src="'.$lrgImage.'">
<img src="'.$medImage.'">
<img src="'.$smlImage.'">
</fieldset><br />
';
}
}
else
{
$info = '<p>No file selected</p>';
}
}
?>
Then the HTML should be as follows:
<h1>Thumbnail Generator</h1>
<form action="" method="post" enctype="multipart/form-data">
<fieldset>
<legend>Upload File & Create Thumbnails</legend>
<input type="file" name="uploaded_file"><input type="submit" name="submit" value=" go ">
</fieldset><br />
</form>
<?
if (!empty($info))
{
echo $info;
}
?>
