Hi everyone,
I have been working on an image gallery to allow people to view/upload their photos. I have everything working pretty well except that I want to modify my upload script so that a thumbnail is generated of each picture that is uploaded and stored in a separate directory with the same name as the original picture. So there would be an "Uploads" directory where all full size images are stored, and then within that directory there would be a "Thumbs" directory where all the thumbnails will be stored (with the same name as the full size image). My script adds the full size image to a table in MySQL, but I DO NOT need the thumbnail in the table(since it will have the same name as the full size image). Here is my script at this point:
<?php
session_id($_POST['current_email']);
session_start();
if (!empty($_FILES)) {
$con = mysql_connect("localhost", "xxx", "xxx") or die("cannot connect");
mysql_select_db("xxx", $con) or die("cannot select DB");
$tempFile = $_FILES["Filedata"]["tmp_name"];
$name = $_FILES["Filedata"]["name"];
$targetPath = "uploads/";
$targetFile = str_replace('//', '/', $targetPath) . $_FILES["Filedata"]['name'];
$size = $_FILES["Filedata"]["size"];
$oext = getExtension($name);
$ext = strtolower($oext);
$whois = $_SERVER['REMOTE_ADDR'];
$email = $_POST['current_email'];
if ($ext == "jpg" || $ext == "jpeg" || $ext == "bmp" || $ext == "gif") {
if ($size < 1024 * 1024) {
if (file_exists("uploads/" . $name)) {
move_uploaded_file($tempFile, "uploads/" . $name);
$qry = "select id from pictures where file='$name' and type='$ext'";
$res = mysql_fetch_array(mysql_query($qry));
$id = $res['id'];
$qry = "UPDATE pictures SET file='$name', type='$ext', size='$size', whois='$whois', date=NOW() where id=$id";
mysql_query($qry);
echo "1";
} else {
move_uploaded_file($tempFile, "uploads/" . $name);
$qry = "INSERT INTO pictures(id, file, type, size, email, whois, date) VALUES ('', '$name', '$ext', '$size', '$email', '$whois', NOW())";
//Start buffering
ob_start();
//print the result
print_r($qry);
//get the result from buffer
$output = ob_get_contents();
//close buffer
ob_end_clean();
//open a file
$h = fopen('log.txt', 'w+');
//write the output text
fwrite($h, $output);
//close file
fclose($h);
mysql_query($qry, $con);
echo "1";
}
}
}
}
function getExtension($image_name)
{
return substr($image_name, strrpos($image_name, '.') + 1);
}
?>
I have googled a few examples, but i am just unsure on how to make it work within my script. And being new to php, something like this takes me days to figure out :P Any help is greatly appreciated!