Ive got some code and a from currently that allow users to upload an image. this image is stored into a folder in my sites root and the filepath to it is stored in a database table along with various other relevant info.
I would like a bit of code that also generates a thumbnail of a given size from this upload and stores it in a thumbnail folder, and also inputs the thumbnail filepath into the database table.
I don't really know where to start... if it helps, here is my upload form code (database connection etc happens before this):
<?
//set up the max filesize ppl can use and add a message variable to display and error type message if someone exceeds the limit. filesize is in bytes, 1mb= 104857 bytes
$maxFileSize=2000000000;
$message="";
//BEGIN FORM SUBMISSION CODE BOII
//these create the variables that we will call on to display later
$imgFileName=$_FILES['imgFile']['name'];
$imgFileTmp=$_FILES['imgFile']['tmp_name'];
$imgFileSize=$_FILES['imgFile']['size'];
$imgFileType=$_FILES['imgFile']['type'];
//END THE FORM SUBMISSION
//if statement for recognising and then displaying and error message when the filesize is higher than the max filesize limit
if($imgFileSize > $maxFileSize){
$message="You're doing it all wrong <br/>";
}
//if statement which looks for the right filetypes, if the wrong filetype is found it displays another message
if($imgFileType=="image/jpeg"|| $imgFileType=="image/gif"){
}else{
$message.="Upload the right filetype you muppet<br/>";
}
//this checks if the filename already exists and echos a message if it has
if(file_exists($filepath)){
$message=" You already done uploaded it you plonka <br/>";
}
//this stops any error messages being shown if their are no issues
if(!isset($imgFileTmp)){
$message="";
}
//if the message is empty, it will upload the file
if($message==""){
move_uploaded_file($imgFileTmp,$filepath);
}
// this tells it to actually upload & where to upload the file to
$filepath="uploads/".$imgFileName;
move_uploaded_file($imgFileTmp,$filepath);
?>
styling bits n bobs go here
<?
//Check to see if the form has been submitted
if(isset($_POST['button'])){
// add the data from the fields into variable so i can use them later
$username = ($_SESSION['userid']);
$title = ($_POST['title']);
$description = ($_POST['description']);
date_default_timezone_set('Europe/London');
$date = date("y-m-d, H:i:s");
//check to see if any of the boxes were not filled in
if(!$title|| !$description){
//if any weren't display the error message
$message=" You need to fill in all of the fields! <br/>";;
}else{
//if not.. go ahead and insert all the info into the sql database
mysql_query("INSERT INTO uploads (username, title, description, filepath, date)
VALUES ('$username', '$title', '$description', '$filepath', '$date')")or die(mysql_error());
//display the success message
$message=" You have successfully uploaded a something! <br/>";
$message2=" Please follow the link below to view the full article<br/>";
?>
I'm using a pretty standard form with an upload button and a couple fields for a description and title. If any one could point em in the right direction or suggest a tutorial I'd appreciate it