hi guys, first post here..... i really hope someone can shed a little light on this for me.
I have a script that uploads a picture from a user, changes its name, and saves it to a dir onmy server.
Now im trying to modify this script to create and save a thumbnail version of the uploaded picture at the same time.
At the moment, i am in a position whwre the script will save an image of the correct size, to the correct location, with the correct name....... but its allways just a black square.
After spending the last 10 hours trying to figure this out, im getting desperate, i need a new pair of eyes to take a glance over this, and i would be very gratefull to anyone who would take the time.
Heres my code:
<?php
session_start();
include("pass.inc");
include("function.inc");
if ( $_SESSION['login'] != "true" )
{
header("location: ../Signup/registration.php");
}
else
{
$connection=mysql_connect($host, $user, $passwd)
or die ("Could not connect !");
$db = mysql_select_db($database, $connection)
or die ("Could not connect to Database");
//--------------------------------------------
if (($_FILES['filename']['type']!="image/jpeg") && ($_FILES['filename']['type']!="image/pjpeg") && ($_FILES['filename']['type']!="image/gif")) {
echo "Sorry you must upload only files of the type .jpg .jpeg or .gif, Click <a href='../picturemanager.php'>Here</a> to try again";
} else {
$query = "SELECT picture1 FROM pictures WHERE user_name='$username'";
$exist = mysql_query($query) or die ("could not Select Picture.");
preg_match('/\.\w{3,4}$/', $_FILES['filename']['name'], $matches);
$new_filename = $_SESSION['username']."1".$matches[0];
$filepath = "member_pics/full_size/".$new_filename;
if (file_exists($filepath)) {
unlink("member_pics/full_size/".$new_filename);
$username = $_SESSION['username'];
}
$source = "member_pics/full_size/";
move_uploaded_file($_FILES['filename']['tmp_name'], "../../$source".$new_filename); // this line is for local host
/*"../xxx/xxx/".$_FILES['filename']['name']);*/ //this line is for remote server
$query = "UPDATE pictures SET picture1 = '$filepath' WHERE user_name='{$_SESSION['username']}'";
$result = mysql_query($query) or die ("could not add picture.");
}
//-------------------------------------****
$query = "SELECT thmb_1 FROM pictures WHERE user_name='$username'";
$exist = mysql_query($query) or die ("could not Select Picture.");
$thmb_filename = $_SESSION['username']."_thmb_1".$matches[0];
$thmb_filepath = "member_pics/thumbnails/".$thmb_filename;
if (file_exists($thmb_filepath)) {
unlink("member_pics/thumbnails/".$thmb_filename);
$username = $_SESSION['username'];
}
//try to create thumbnail
// Get original width and height
$image = imagecreatefromjpeg("../../".$filepath);
if ($image === false) {
die ('Unable to open image');
}
$width = imagesx($image);
$height = imagesy($image);
// New width and height
$new_hieght = 100;
$new_width = 100;
// Resample
$image_resized = imagecreate($new_hieght,$new_width);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);;
$save = "../../member_pics/thumbnails/".$thmb_filename;
imagejpeg($image_resized, $save);
imagedestroy($image);
imagedestroy($image_resized);
$query = "UPDATE pictures SET thmb_1 = '$thmb_filepath' WHERE user_name='{$_SESSION['username']}'";
$result = mysql_query($query) or die ("could not add picture.");
}
?>
So the file is passed to this script from an upload form, then the first section of code deals with renaming and storing the full size image.
Thanks agin to anybody who takes a look.....
Desperatly...
Accura