WilliamMute007
Programmer
Hi all,
am really really baffled about this script which seems correct to me but for some reason doesnt do what its suppose to. Any help is MUCH appreciated
The code is suppose to take info from a form username, name, surname AND a thumbnail image of the user and store the details in the DB and upload the image to my designated path. see code below
Thanks for all your possible help.
am really really baffled about this script which seems correct to me but for some reason doesnt do what its suppose to. Any help is MUCH appreciated
The code is suppose to take info from a form username, name, surname AND a thumbnail image of the user and store the details in the DB and upload the image to my designated path. see code below
Code:
<?php require_once('../connection.php');?>
<?php
$username = $_POST['school_type_nursery'];
$pass = $_POST['school_type_primary'];
$first_name = $_POST['school_type_secondary'];
$surname = $_POST['school_type_nursery'];
$part = $_POST['school_type_primary'];
$member_since = $_POST['school_type_secondary'];
$phone = $_POST['school_type_nursery'];
$email = $_POST['school_type_primary'];
$birthday = $_POST['school_type_secondary'];
$local_area = $_POST['school_type_nursery'];
$image = $_POST['image'];
print_r($_POST); //debug the incoming vars
if(isset($_POST['Submit'])) {
mysql_pconnect($hostname_Connection, $username_Connection, $password_Connection)
or die("Unable to connect to db " . mysql_error());
mysql_select_db($database_Connection)
or die("unable to select database. ". mysql_error());
$query =
"INSERT INTO `mediamind1`.`choir_list` (
`id` ,
`username` ,
`pass` ,
`first_name` ,
`surname` ,
`part_singing` ,
`picture` ,
`date_joined` ,
`contact_number` ,
`email_address` ,
`birthday` ,
`local_area`
)
VALUES (
NULL , '$username', '$pass', '$first_name', '$surname', '$part', '$image', '$member_since', '$phone', '$email', '$birthday', '$local_area')";
mysql_query ($query)
or die("There was a failure putting the required destination into the database, please try again ".mysql_error());
die("<META http-equiv=\"Refresh\" content=\"0;url=/../index.php\">");
}
else
{
die("<META http-equiv=\"Refresh\" content=\"0;url=fail.php\">");
}
$id = $keyword;
$imagePath = "thumbs/";
//--- Check against the max file size
$size = basename($_FILES['image']['size']);
//die("siz".$size);
$maxSize = round(2 * 1024 * 1024); //2mb
if($size > $maxSize) {
echo "The file is to large to upload<br />";
echo "<br />";
echo "Your File Size: ".$size." (bytes)<br />";
echo "Max File Size: ".$maxSize." (bytes)<br />";
echo "<br />";
echo '<a href="upload_school_badge.php" >Press Here</a> to return to the upload page<br />';
die("");
}
//--- This gets all the other information from the form
$pic=($_FILES['image']['name']);
//--- Check the file Suffix / Length (.jpg OR .gif AND )
if (strlen($pic) < 5){
die ("File String Appears to be to short (Less than 5 characters)");
}
$FileSuffix = substr( $pic, strlen($pic) - 4 );
if ($FileSuffix != ".jpg" and $FileSuffix != ".gif"){
die("we do not support that type of file, We Only support JPG or GIF");
}
//--- Ensure a something has been uploaded
if( $pic == ""){
?>
No file was selected to be uploaded<br />
<a href="upload.php">Please Try Again</a>
<?PHP
die("");
}
//--- Connect to the database
mysql_pconnect($hostname_Connection, $username_Connection, $password_Connection)
or die("Unable to connect to db " . mysql_error());
mysql_select_db($database_Connection)
or die("unable to select database. ". mysql_error());
//--- Upload the file
//Create target Path
$target = $imagePath.basename( $_FILES['image']['name']);
// Ensure the file doesn't exist
if( file_exists($target)){
echo "That file already exists";
echo '<a href="upload_school_badge.php">Please Try Again</a>';
die("");
}
if(move_uploaded_file($_FILES['image']['tmp_name'], $target))
{
//Tells you if its all ok
echo "<h2>The file has succesfully been uploaded</h2>";
echo "<br />";
echo "<a href='../index.php'>Go to the Homepage</a>";
$filename = $target;
$size = getimagesize($filename);
$width = $size[0];
$height = $size[1];
//--- Writes the information to the database
//mysql_query("INSERT INTO tblPic (picname,gallery,width,height,userID) VALUES('$pic','$galleryName','$width','$height','$userID') ") or die(mysql_error());
//--- Generate A Master Thumb of the image, (To Save Memory)
if(true){
$startX = 0;
$startY = 0;
// image to crop
$image = $imagePath.$pic;
// dest image that is generated (either Thumbs Or Main)
$dest_image = $imagePath.'thumbs/'.$pic;
// get master image dimensions
$ims = getimagesize($image);
//calc new width / height to fit in the view port
$viewWidth = 200;
$viewHeight = 200;
$masterWidth = $ims[0];
$masterHeight = $ims[1];
//Calc Master image size to fit in the View Port
$ratioWidth = $masterWidth / $viewWidth;
$ratioHeight = $masterHeight / $viewHeight;
if( $ratioWidth < 1 && $ratioHeight < 1){
$ratioWidth = 1;
$ratioHeight = 1;
}
if($ratioWidth > $ratioHeight){
$imgWidth = $masterWidth / $ratioWidth;
$imgHeight = $masterHeight / $ratioWidth;
} else {
$imgWidth = $masterWidth / $ratioHeight;
$imgHeight = $masterHeight / $ratioHeight;
}
// Create / resize etc
$img = imagecreatetruecolor($imgWidth,$imgHeight);
$org_img = imagecreatefromjpeg($image);
imagecopyresampled($img,$org_img,0,0,0,0,$imgWidth,$imgHeight,$ims[0], $ims[1]);
imagejpeg($img,$dest_image,100);
?>
<img src="<?php echo $dest_image; ?>" />
<?php
}
} else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
Thanks for all your possible help.