i want to create an upload utility that allows upload then automatically generates a thumbnail i found 2 scripts that i would like to merge any help in doing this as i get multiple parse errors
😕
SCRIPT 1
/* Thumbnail.php, (c) 2002 Martin Glassborow <spell@spellen.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
<?php
function thumbnail ($picture,$thumbnail_width) {
global $pathtopictures;
$imagename = "$pathtopictures/$picture";
$thumbnail = "$picture-thumb";
$imagesize = GetImageSize("$pathtopictures/$picture");
$image_width = $imagesize[0];
$image_height =$imagesize[1];
$image_type = $imagesize[2];
$image_ratio = $image_width / $thumbnail_width;
$thumbnail_height = $image_height / $image_ratio ;
if ($image_type == '2') {
$new_image = ImageCreate ($thumbnail_width, $new_height);
$old_image = imageCreateFromJPEG("$imagename");
ImageCopyResized($new_image, $old_image, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $image_width, $image_height);
ImageJpeg($new_image,"$thumbnail",80);
ImageDestroy($new_image);
copy($thumbnail, "$pathtopictures/$thumbnail");
unlink($thumbnail);
return true;
} elseif ($image_type == '3' {
$new_image = ImageCreate ($thumbnail_width, $new_height);
$old_image = imageCreateFromPNG("$imagename");
ImageCopyResized($new_image, $old_image, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $image_width, $image_height);
ImagePNG($new_image,"$thumbnail");
ImageDestroy($new_image);
copy($thumbnail, "$pathtopictures/$thumbnail");
unlink($thumbnail);
return true;
} else {
print "Could not handle this type of image";
return false;
}
}
?>
SCRIPT 2
<?
if (isset($users_file)) {
echo "<B>Remote File Name:</B> $users_file<BR>";
echo "<B>Local File Name:</B> $users_file_name<BR>";
echo "<B>Local File Size:</B> $users_file_size<BR>";
if (isset($users_file_type)) {
echo "<B>Local File Type:</B> $users_file_type<P>"; }
// Change $doc_directory to your 'DocumentRoot'.
$doc_directory = "upload directory";
$my_file = "uploaded-".$users_file_name;
$copy_path = $doc_directory.$my_file;
if ($users_file != "none") {
if(!copy($users_file, $copy_path)) {
echo "File upload failed!"; }
else { ?><A HREF="<? echo $my_file; ?>">Upload Complete!</A>
<? } }
else { echo "<P>You must select a file to upload!<P>"; ?>
<A HREF="<? echo $PHP_SELF; ?>"><B>Back</B></A> to the Upload Form
<? } }
else { ?>
<form action="<? echo $PHP_SELF; ?>"
enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
<input type="file" name="users_file" /><br />
<input type="submit" value="Upload!" />
</form><? } ?>