Thumbnail Generator

webgoonie
11:12:11
Why is it not even recognizing the file and it's saying unable to open file we'll my issue is that it's uploading to main folder but now I can't get a handle on the thumnail generator and it doesn't upload it. Also I had to input.

Can anyone help me with this?

<?php
//***************************************
// This is downloaded from www.plus2net.com //
// Please don't remove the link to www.plus2net.com ///
// This is for your learning only not for commercial use. ///////
//The author is not responsible for any type of loss or problem or damage on using this script.//
/// You can use it at your own risk. /////
//*****************************************
?>

<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>Auto Thumbnail generation script from plus2net.com</title>
</head>

<body >
<?php

// Below lines are to display file name, temp name and file type , you can use them for testing your script only//////
echo "File Name: ".$_FILES['userfile']['name']."<br>";
echo "tmp name: ".$_FILES['userfile']['tmp_name']."<br>";
echo "File Type: ".$_FILES['userfile']['type']."<br>";
echo "<br><br>";
///////////////////////////////////////////////////////////////////////////


$add="upimg/".$_FILES['userfile']['name']; // the path with the file name where the file will be stored, upload is the directory name.
//echo $add;
if(move_uploaded_file ($_FILES['userfile']['tmp_name'],'$add')){
echo "Successfully uploaded the image"."<br>";
chmod('$add',0777);

}else{echo "Failed to upload file Contact Site admin to fix the problem";
exit;}

///////// Start the thumbnail generation//////////////


$n_width = '100'; // Fix the width of the thumb nail images
$n_height= '100'; // Fix the height of the thumb nail imaage

$tsrc="thimg/".$_FILES['userfile']['name']."<br>"; // Path where thumb nail image will be stored

echo $tsrc;

if (!($_FILES['userfile']['type'] =="image/pjpeg" OR $_FILES['userfile']['type']=="image/gif")){
echo "Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>";
exit;
}
/////////////////////////////////////////////// Starting of GIF thumb nail creation///////////


if ($_FILES['userfile']['type']=="image/gif")
{
$im=ImageCreateFromGIF($add);
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
if (function_exists("imagegif")) {
Header("Content-type: image/gif");
ImageGIF($newimage,$tsrc);
}
elseif (function_exists("imagejpeg")) {
Header("Content-type: image/jpeg");
ImageJPEG($newimage,$tsrc);
}
chmod("$tsrc",0777);
}////////// end of gif file thumb nail creation//////////



////////////// starting of JPG thumb nail creation//////////


if($_FILES['userfile']['type']=="image/jpeg"){
$im=ImageCreateFromJPEG('$add');
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
ImageJpeg($newimage,$tsrc);
//chmod($tsrc,0777);
}



//////////////// End of JPG thumb nail creation //////////
?>


<center><a href='http://www.plus2net.com'>PHP SQL HTML free tutorials and scripts</a></center>
</body>

</html>



////////////// This is my echo screen..//////////


File Name: DSC05658.jpg
tmp name: C:\wamp\tmp\php76C4.tmp
File Type: image/jpeg


Successfully uploaded the image
thimg/DSC05658.jpg
Your uploaded file must be of JPG or GIF. Other file types are not allowed

/////////////// Why isn't the thumbnail being generated? ////////////////// it's crashing out.
webgoonie
11-12-2011
Well I finally fixed it, play around with some stuff and I'll share this with everyone, this definetly works totally.

<?php
//***************************************
// This is downloaded from www.plus2net.com //
// Please don't remove the link to www.plus2net.com ///
// This is for your learning only not for commercial use. ///////
//The author is not responsible for any type of loss or problem or damage on using this script.//
/// You can use it at your own risk. /////
//*****************************************
?>

<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>Auto Thumbnail generation script from plus2net.com</title>
</head>

<body >
<?php

// Below lines are to display file name, temp name and file type , you can use them for testing your script only//////
echo "<b>User File Name:</b> ".$_FILES['userfile']['name']."<br>";
echo "<b>User File tmp name:</b> ".$_FILES['userfile']['tmp_name']."<br>";
echo "<b>User File Type:</b> ".$_FILES['userfile']['type']."<br>";
echo "<br><br>";
///////////////////////////////////////////////////////////////////////////
$add="upimg/".$_FILES['userfile']['name']; // the path with the file name where the file will be stored, upload is the directory name.
//echo $add;

if(move_uploaded_file ($_FILES['userfile']['tmp_name'],$add)){
echo "Successfully uploaded the image"."<br>";
chmod('$add',0777);

}else{echo "Failed to upload image file Please Contact Site admin to fix the problem";
exit;}


///////// Start the thumbnail generation//////////////
$n_width=100; // Fix the width of the thumb nail images
$n_height=100; // Fix the height of the thumb nail imaage

$tsrc="thimg/".$_FILES['userfile']['name']; // Path where thumb nail image will be stored
echo $tsrc;


if ((!$_FILES['userfile']['type'] =='image/pjpeg' OR $_FILES['userfile']['type']=='image/gif')){echo "Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>";
exit;}



/////////////////////////////////////////////// Starting of GIF thumb nail creation///////////


if ($_FILES['userfile']['type']=="image/gif")
{
$im=ImageCreateFromGIF($add);
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
if (function_exists("imagegif")) {
Header("Content-type: image/gif");
ImageGIF($newimage,$tsrc);
}
elseif (function_exists("imagejpeg")) {
Header("Content-type: image/jpeg");
ImageJPEG($newimage,$tsrc);
}
chmod("$tsrc",0777);
}////////// end of gif file thumb nail creation//////////



////////////// starting of JPG thumb nail creation//////////


if($_FILES['userfile']['type']=="image/jpeg"){
$im=ImageCreateFromJPEG('$add');
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
ImageJpeg($newimage,$tsrc);
//chmod($tsrc,0777);
}



//////////////// End of JPG thumb nail creation //////////
?>


<center><a href='http://www.plus2net.com'>PHP SQL HTML free tutorials and scripts</a></center>
</body>

</html>
Please Login to post your reply or start a new topic