WilliamMute007
Programmer
Hi Guys,
I have a bit of problem here. I have a page which basically uploads a set of info together with an image. Now I now tried to implement image resizing to the image being uploaded so i can have a thumbnail but here comes disaster! Help Please.. It works without the image resizing. Please see code below and help.
Thank you for your help in advance
I have a bit of problem here. I have a page which basically uploads a set of info together with an image. Now I now tried to implement image resizing to the image being uploaded so i can have a thumbnail but here comes disaster! Help Please.. It works without the image resizing. Please see code below and help.
Code:
require_once("settings.php"); //Load the settings
$alert = ""; //Alert message after actions
// Upload action
if(isset($_FILES['file'])) {
$extension = pathinfo($_FILES['file']['name']);
$extension = $extension["extension"];
$allowed_paths = explode(", ", $allowed_ext); //if any file is uploaded loads the allowed_ext from settings.php and explode the array
$valid = 0;
for($i = 0; $i < count($allowed_paths); $i++) {
if ($allowed_paths[$i] == "$extension") {
$valid = 1; // valid = 1 only if the extension is allowed in "settings.php" file
}
}
if ($valid == 1 && $_FILES["file"]["size"] <= $max_weight) {
if (file_exists("upload/" . $_FILES["file"]["name"])) {
$alert = '<p class="error">' . $_FILES["file"]["name"] . ' already exist!' . '</p>'; //the file already exists
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
$scr = $_FILES["file"]["tmp_name"];
list($width,$height)=getimagesize($_FILES["file"]["tmp_name"]);
$newwidth=60;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
$newwidth1=25;
$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 = "upload/". $_FILES['file']['name'];
$filename1 = "upload/small". $_FILES['file']['name'];
imagejpeg($tmp,$filename,100);
imagejpeg($tmp1,$filename1,100);
imagedestroy($src);
imagedestroy($tmp);
imagedestroy($tmp1);
$save = $_FILES["file"]["name"]; //It stores the name of the file in a variable
$mysql = mysql_connect($db_host, $db_user, $db_password);
mysql_select_db($db_name, $mysql);
$sql = "INSERT INTO $table_name (FirstName, LastName, Title, summary, other, File) VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[title]','$_POST[summary]','$_POST[other]','upload/$save')"; //stores records in database
mysql_query($sql, $mysql);
$alert = '<p class="ok">' . 'Successfuly Added!' . '</p>';
mysql_close($mysql);
}
} else {
$alert = '<p class="error">' . 'Invalid file type!' . '</p>'; //the extension is not supported or the wight file is too big
}
}
?>
Thank you for your help in advance