WilliamMute007
Programmer
Hi All,
I have a script which basically uploades an image to folder (unique folder) each time.
I wanted to extend this script so that when it uploads the image, it should ALSO create a small thumbnail of it so I'll have the original and a small version. I want to store the two images in the same folder with the smaller one simply having "small" or something of that nature appended to the end of the original file name so I can distinguish the two.
The main script works perfectly but I have been having problems for over a day now with the resizing. Please see if you can help... Script below
I appreciate your help in advance please.
Thank you
I have a script which basically uploades an image to folder (unique folder) each time.
I wanted to extend this script so that when it uploads the image, it should ALSO create a small thumbnail of it so I'll have the original and a small version. I want to store the two images in the same folder with the smaller one simply having "small" or something of that nature appended to the end of the original file name so I can distinguish the two.
The main script works perfectly but I have been having problems for over a day now with the resizing. Please see if you can help... Script below
Code:
<?
include('verify.php');
$title = $_POST['title'];
$text = $_POST['text'];
$categorie = $_POST['categorie'];
$categorie_name = $_POST['categorie_name'];
$author = $_POST['author'];
// Call for the name of categorie
$queryd = "SELECT * FROM $table_d WHERE id_cat=$categorie";
$resultd = mysql_query($queryd);
$mycat = @mysql_fetch_object($resultd);
$categorie_name = $mycat->categorie_name;
// LAST INCREMENTATION
$queryz = "SELECT last FROM $table_g";
$resultz = mysql_query($queryz);
$incr = @mysql_fetch_object($resultz);
$nrowss = $incr->last;
// NEW ID
$id= $nrowss+1;
umask(0000);
mkdir('../appreciateduploads/'.$id.'', 0777);
// Folder blog + id of the new article
$uploadDir = '../appreciateduploads/'.$id.'/';
// Image file data
$fileName = $_FILES['preview']['name'];
$tmpName = $_FILES['preview']['tmp_name'];
// File extension extraction
$ext = substr(strrchr($fileName, "."), 1);
// File extension verification
if ($ext != "jpg" ) {
echo ("Only jpg file are accepted (extension .jpg) Thanks !");
exit;
}
// Generate random name
$randName = md5(rand() * time());
// Creation of path
$filePath = $uploadDir . $fileName;
$newfilename = $fileName;
list($width,$height)=getimagesize($tmpName, $filePath);
$newwidth=60;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
$newwidth1=150; //This is where I set the width of the thumbnail
$newheight1=($height/$width)*$newwidth1;
$tmp1=imagecreatetruecolor($newwidth1,$newheight1);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,
$width,$height);
imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,
$width,$height);
$filename = "../"$filePath"/". $_FILES['preview']['name'];
$filename1 = "../"$filePath"small". $_FILES['preview']['name'];
//$filename = "upload/". $_FILES['file']['name']; //This is where I decide where to store the original image. Same size as the thumb
$filename1 = ($tmpName,$filePath ["small"]);
//imagejpeg($tmp,$filename,100);
imagejpeg($tmpName,$filename1,100);
// UPLOAD IMAGE
// If something wrong.... we stop ! or we upload.
$result = move_uploaded_file($tmpName, $filename1, $filePath);
if (!$result) {
echo "Error during upload... Please try again or request assistant.";
exit;
}
$date_post = date("Y-m-d H:i:s");
$insert = mysql_query("INSERT INTO $table_b
(
title,
text,
preview,
categorie,
categorie_name,
author,
date_post
)
VALUES
(
'$title',
'$text',
'$newfilename',
'$categorie',
'$categorie_name',
'$author',
'$date_post'
)") or die(mysql_error());
if(!$insert) echo alert("Error during insert...");
$update = mysql_query("UPDATE $table_g SET last='$id'");
if(!$update) echo alert("Error during update...");
header("location:update_rss.php");
?>
I appreciate your help in advance please.
Thank you