jacko_162 Posted September 13, 2011 Share Posted September 13, 2011 I have a working image upload script that uploads, renames the file and adds filename to the database. is it possible to include some sort of image resize code? if so can anyone point me in the right direction or better still show some example code and explain how it works etc. below is my working code: <?php $rand = mt_rand(1,9999999); $member_id = $_SESSION['SESS_MEMBER_ID']; $caption = $_POST["caption"]; if(isset($_FILES['uploaded']['name'])) { $allowed_filetypes = array('.jpg','.gif','.bmp','.png','.jpeg'); $max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB) $fileName = basename($_FILES['uploaded']['name']); $errors = array(); $target = "gallery/"; $fileBaseName = substr($fileName, 0, strripos($fileName, '.')); // Get the extension from the filename. $ext = substr($fileName, strpos($fileName,'.'), strlen($fileName)-1); //$newFileName = md5($fileBaseName) . $ext; $newFileName = $target . $rand . "_" . $member_id.$ext; // Check if filename already exists if(file_exists("gallery/" . $newFileName)) { $errors[] = "The file you attempted to upload already exists, please try again."; } // Check if the filetype is allowed. if(!in_array($ext,$allowed_filetypes)) { $errors[] = "The file you attempted to upload is not allowed."; } // Now check the filesize. if(!filesize($_FILES['uploaded']['tmp_name']) > $max_filesize) { $errors[] = "The file you attempted to upload is too large."; } // Check if we can upload to the specified path. if(!is_writable($target)) { $errors[] = "You cannot upload to the specified directory, please CHMOD it to 777."; } //Here we check that no validation errors have occured. if(count($errors)==0) { //Try to upload it. if(!move_uploaded_file($_FILES['uploaded']['tmp_name'], $newFileName)) { $errors[] = "Sorry, there was a problem uploading your file."; } } //Lets INSERT database information here if(count($errors)==0) { $result = mysql_query("INSERT INTO `gallery` (`image`, `memberid`, `caption`) VALUES ('$newFileName', '$member_id', '$caption')") or die (mysql_error()); } //If no errors show confirmation message if(count($errors)==0) { echo "<div class='notification success png_bg'> <a href='#' class='close'><img src='img/cross_grey_small.png' title='Close this notification' alt='close' /></a> <div> Image has been uploaded.<br>\n </div> </div>"; //echo "The file {$fileName} has been uploaded"; echo "<br>\n"; echo "<a href='gallery.php'>Go Back</a>\n"; } else { //show error message echo "<div class='notification attention png_bg'> <a href='#' class='close'><img src='img/cross_grey_small.png' title='Close this notification' alt='close' /></a> <div> Sorry your file was not uploaded due to the following errors:<br>\n </div> </div>"; //echo "Sorry your file was not uploaded due to the following errors:<br>\n"; echo "<ul>\n"; foreach($errors as $error) { echo "<li>{$error}</li>\n"; } echo "</ul>\n"; echo "<br>\n"; echo "<a href='gallery.php'>Go Back</a>\n"; } } else { //Show the form echo "Use the following form below to add a new image to your gallery;<br /><br />\n"; echo "<form enctype='multipart/form-data' action='' method='POST'>\n"; echo "Please choose a file:<br /><input class='text' name='uploaded' type='file' /><br />\n"; echo "Image Caption:<br /><input class='text' name='caption' type='text' value='' /><br /><br />\n"; echo "<input class='Button' type='submit' value='Upload' />\n"; echo "</form>\n"; } ?> Many thanks to phpfreaks again. Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/ Share on other sites More sharing options...
jacko_162 Posted September 13, 2011 Author Share Posted September 13, 2011 ok i found the following on the net: http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/ how would i go about adding said code (from source) into my code? any help mucho appreciated Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1268985 Share on other sites More sharing options...
xyph Posted September 13, 2011 Share Posted September 13, 2011 Copying and pasting? This isn't really 'helping' you with PHP, is it? Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1268988 Share on other sites More sharing options...
jacko_162 Posted September 13, 2011 Author Share Posted September 13, 2011 help is what im after but i have no idea how to impliment said code as some things contradict my already working code.. Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1268991 Share on other sites More sharing options...
xyph Posted September 13, 2011 Share Posted September 13, 2011 Perhaps you should worry about understanding the code before implementing it? What happens when something goes wrong or a user inputs a parameter the script doesn't expect? How would you debug code you don't understand? Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1269000 Share on other sites More sharing options...
jacko_162 Posted September 14, 2011 Author Share Posted September 14, 2011 ok i decided to take advise and try to learn how the code works, im still pretty confused but i think i have the basics (well the theory anyways, putting into practice is proving more difficult) so i decided to use the class found here: http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/ and implimented it before i upload the file using: move_uploaded_file($_FILES['uploaded']['tmp_name'] this is now my code: <?php $rand = mt_rand(1,9999999); $member_id = $_SESSION['SESS_MEMBER_ID']; $caption = $_POST["caption"]; if(isset($_FILES['uploaded']['name'])) { $allowed_filetypes = array('.jpg','.gif','.bmp','.png','.jpeg'); $max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB) $fileName = basename($_FILES['uploaded']['name']); $errors = array(); $target = "gallery/"; $fileBaseName = substr($fileName, 0, strripos($fileName, '.')); // Get the extension from the filename. $ext = substr($fileName, strpos($fileName,'.'), strlen($fileName)-1); //$newFileName = md5($fileBaseName) . $ext; $newFileName = $target . $rand . "_" . $member_id.$ext; // Check if filename already exists if(file_exists("gallery/" . $newFileName)) { $errors[] = "The file you attempted to upload already exists, please try again."; } // Check if the filetype is allowed. if(!in_array($ext,$allowed_filetypes)) { $errors[] = "The file you attempted to upload is not allowed."; } // Now check the filesize. if(!filesize($_FILES['uploaded']['tmp_name']) > $max_filesize) { $errors[] = "The file you attempted to upload is too large."; } // Check if we can upload to the specified path. if(!is_writable($target)) { $errors[] = "You cannot upload to the specified directory, please CHMOD it to 777."; } //Here we check that no validation errors have occured. if(count($errors)==0) { //Load Class File to resize images include('Includes/SimpleImage.php'); //Load image to resize $image = new SimpleImage(); $image->load($_FILES['uploaded']['tmp_name']); $image->resizeToWidth(25); //Try to upload it. if(!move_uploaded_file($_FILES['uploaded']['tmp_name'], $newFileName)) { $errors[] = "Sorry, there was a problem uploading your file."; } } //Lets INSERT database information here if(count($errors)==0) { $result = mysql_query("INSERT INTO `gallery` (`image`, `memberid`, `caption`) VALUES ('$newFileName', '$member_id', '$caption')") or die (mysql_error()); } //If no errors show confirmation message if(count($errors)==0) { echo "<div class='notification success png_bg'> <a href='#' class='close'><img src='img/cross_grey_small.png' title='Close this notification' alt='close' /></a> <div> Image has been uploaded.<br>\n </div> </div>"; //echo "The file {$fileName} has been uploaded"; echo "<br>\n"; echo "<a href='gallery.php'>Go Back</a>\n"; } else { //show error message echo "<div class='notification attention png_bg'> <a href='#' class='close'><img src='img/cross_grey_small.png' title='Close this notification' alt='close' /></a> <div> Sorry your file was not uploaded due to the following errors:<br>\n </div> </div>"; //echo "Sorry your file was not uploaded due to the following errors:<br>\n"; echo "<ul>\n"; foreach($errors as $error) { echo "<li>{$error}</li>\n"; } echo "</ul>\n"; echo "<br>\n"; echo "<a href='gallery.php'>Go Back</a>\n"; } } else { //Show the form echo "Use the following form below to add a new image to your gallery;<br /><br />\n"; echo "<form enctype='multipart/form-data' action='' method='POST'>\n"; echo "Please choose a file:<br /><input class='text' name='uploaded' type='file' /><br />\n"; echo "Image Caption:<br /><input class='text' name='caption' type='text' value='' /><br /><br />\n"; echo "<input class='Button' type='submit' value='Upload' />\n"; echo "</form>\n"; } ?> the form processes without error, but unfortunatly doesnt resize the image used. after uploading. what did i do wrong? as i cant find out if anything did go wrong with the resize as its not reporting errors. Many thanks thus far. Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1269168 Share on other sites More sharing options...
voip03 Posted September 14, 2011 Share Posted September 14, 2011 Resizing images with PHP follow the line line from 44 ->105 in your link Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1269179 Share on other sites More sharing options...
jacko_162 Posted September 14, 2011 Author Share Posted September 14, 2011 i saw that from line 44 > 105 it tried to pullvariable $filename where i had $fileName (capital) n, i changed that in my code but still not processing the function class. how can i get it to produce error checks and echo them? Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1269206 Share on other sites More sharing options...
voip03 Posted September 14, 2011 Share Posted September 14, 2011 Where is that code? Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1269211 Share on other sites More sharing options...
jacko_162 Posted September 14, 2011 Author Share Posted September 14, 2011 these are my 2 pages: add.php <?php $rand = mt_rand(1,9999999); $member_id = $_SESSION['SESS_MEMBER_ID']; $caption = $_POST["caption"]; if(isset($_FILES['uploaded']['name'])) { $allowed_filetypes = array('.jpg','.gif','.bmp','.png','.jpeg'); $max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB) $filename = basename($_FILES['uploaded']['name']); $errors = array(); $target = "gallery/"; $fileBaseName = substr($filename, 0, strripos($filename, '.')); // Get the extension from the filename. $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); //$newfilename = md5($fileBaseName) . $ext; $newfilename = $target . $rand . "_" . $member_id.$ext; // Check if filename already exists if(file_exists("gallery/" . $newfilename)) { $errors[] = "The file you attempted to upload already exists, please try again."; } // Check if the filetype is allowed. if(!in_array($ext,$allowed_filetypes)) { $errors[] = "The file you attempted to upload is not allowed."; } // Now check the filesize. if(!filesize($_FILES['uploaded']['tmp_name']) > $max_filesize) { $errors[] = "The file you attempted to upload is too large."; } // Check if we can upload to the specified path. if(!is_writable($target)) { $errors[] = "You cannot upload to the specified directory, please CHMOD it to 777."; } //Here we check that no validation errors have occured. if(count($errors)==0) { //Load Class File to resize images include('Includes/SimpleImage.php'); //Load image to resize $image = new SimpleImage(); $image->load($_FILES['uploaded']['tmp_name']); $image->resizeToWidth(25); //Try to upload it. if(!move_uploaded_file($_FILES['uploaded']['tmp_name'], $newfilename)) { $errors[] = "Sorry, there was a problem uploading your file."; } } //Lets INSERT database information here if(count($errors)==0) { $result = mysql_query("INSERT INTO `gallery` (`image`, `memberid`, `caption`) VALUES ('$newfilename', '$member_id', '$caption')") or die (mysql_error()); } //If no errors show confirmation message if(count($errors)==0) { echo "<div class='notification success png_bg'> <a href='#' class='close'><img src='img/cross_grey_small.png' title='Close this notification' alt='close' /></a> <div> Image has been uploaded.<br>\n </div> </div>"; //echo "The file {$filename} has been uploaded"; echo "<br>\n"; echo "<a href='gallery.php'>Go Back</a>\n"; } else { //show error message echo "<div class='notification attention png_bg'> <a href='#' class='close'><img src='img/cross_grey_small.png' title='Close this notification' alt='close' /></a> <div> Sorry your file was not uploaded due to the following errors:<br>\n </div> </div>"; //echo "Sorry your file was not uploaded due to the following errors:<br>\n"; echo "<ul>\n"; foreach($errors as $error) { echo "<li>{$error}</li>\n"; } echo "</ul>\n"; echo "<br>\n"; echo "<a href='gallery.php'>Go Back</a>\n"; } } else { //Show the form echo "Use the following form below to add a new image to your gallery;<br /><br />\n"; echo "<form enctype='multipart/form-data' action='' method='POST'>\n"; echo "Please choose a file:<br /><input class='text' name='uploaded' type='file' /><br />\n"; echo "Image Caption:<br /><input class='text' name='caption' type='text' value='' /><br /><br />\n"; echo "<input class='Button' type='submit' value='Upload' />\n"; echo "</form>\n"; } ?> Includes/SimpleImage.php <?php /* * File: SimpleImage.php * Author: Simon Jarvis * Copyright: 2006 Simon Jarvis * Date: 08/11/06 * Link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * http://www.gnu.org/licenses/gpl.html * */ class SimpleImage { var $image; var $image_type; function load($filename) { $image_info = getimagesize($filename); $this->image_type = $image_info[2]; if( $this->image_type == IMAGETYPE_JPEG ) { $this->image = imagecreatefromjpeg($filename); } elseif( $this->image_type == IMAGETYPE_GIF ) { $this->image = imagecreatefromgif($filename); } elseif( $this->image_type == IMAGETYPE_PNG ) { $this->image = imagecreatefrompng($filename); } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image,$filename,$compression); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image,$filename); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image,$filename); } if( $permissions != null) { chmod($filename,$permissions); } } function output($image_type=IMAGETYPE_JPEG) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image); } } function getWidth() { return imagesx($this->image); } function getHeight() { return imagesy($this->image); } function resizeToHeight($height) { $ratio = $height / $this->getHeight(); $width = $this->getWidth() * $ratio; $this->resize($width,$height); } function resizeToWidth($width) { $ratio = $width / $this->getWidth(); $height = $this->getheight() * $ratio; $this->resize($width,$height); } function scale($scale) { $width = $this->getWidth() * $scale/100; $height = $this->getheight() * $scale/100; $this->resize($width,$height); } function resize($width,$height) { $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1269220 Share on other sites More sharing options...
voip03 Posted September 14, 2011 Share Posted September 14, 2011 Try this one <?php error_reporting(0); $change=""; $abc=""; define ("MAX_SIZE","400"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if($_SERVER["REQUEST_METHOD"] == "POST") { $image =$_FILES["file"]["name"]; $uploadedfile = $_FILES['file']['tmp_name']; if ($image) { $filename = stripslashes($_FILES['file']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { $change='<div class="msgdiv">Unknown Image extension </div> '; $errors=1; } else { $size=filesize($_FILES['file']['tmp_name']); if ($size > MAX_SIZE*1024) { $change='<div class="msgdiv">You have exceeded the size limit!</div> '; $errors=1; } if($extension=="jpg" || $extension=="jpeg" ) { $uploadedfile = $_FILES['file']['tmp_name']; $src = imagecreatefromjpeg($uploadedfile); } else if($extension=="png") { $uploadedfile = $_FILES['file']['tmp_name']; $src = imagecreatefrompng($uploadedfile); } else { $src = imagecreatefromgif($uploadedfile); } echo $scr; list($width,$height)=getimagesize($uploadedfile); $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 = "uploads/". $_FILES['file']['name']; $filename1 = "uploads/small". $_FILES['file']['name']; imagejpeg($tmp,$filename,100); imagejpeg($tmp1,$filename1,100); imagedestroy($src); imagedestroy($tmp); imagedestroy($tmp1); }} } //If no errors registred, print the success message if(isset($_POST['Submit']) && !$errors) { // mysql_query("update {$prefix}users set img='$big',img_small='$small' where user_id='$user'"); $change=' <div class="msgdiv">Image Uploaded Successfully!</div>'; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <meta content="en-us" http-equiv="Content-Language"> <title>picture demo</title> <link href=".css" media="screen, projection" rel="stylesheet" type="text/css"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script> <script type="text/javascript" src="js/jquery_002.js"></script> <script type="text/javascript" src="js/displaymsg.js"></script> <script type="text/javascript" src="js/ajaxdelete.js"></script> <style type="text/css"> .help { font-size:11px; color:#006600; } body { color: #000000; background-color:#999999 ; background:#999999 url(<?php echo $user_row['img_src']; ?>) fixed repeat top left; font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif; } .msgdiv{ width:759px; padding-top:8px; padding-bottom:8px; background-color: #fff; font-weight:bold; font-size:18px;-moz-border-radius: 6px;-webkit-border-radius: 6px; } #container{width:763px;margin:0 auto;padding:3px 0;text-align:left;position:relative; -moz-border-radius: 6px;-webkit-border-radius: 6px; background-color:#FFFFFF } </style> </head><body> <div align="center" id="err"> <?php echo $change; ?> </div> <div id="space"></div> <div id="container" > <div id="con"> <table width="502" cellpadding="0" cellspacing="0" id="main"> <tbody> <tr> <td width="500" height="238" valign="top" id="main_right"> <div id="posts"> <img src="<?php echo $filename; ?>" /> <img src="<?php echo $filename1; ?>" /> <form method="post" action="" enctype="multipart/form-data" name="form1"> <table width="500" border="0" align="center" cellpadding="0" cellspacing="0"> <tr><Td style="height:25px"> </Td></tr> <tr> <td width="150"><div align="right" class="titles">Picture : </div></td> <td width="350" align="left"> <div align="left"> <input size="25" name="file" type="file" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10pt" class="box"/> </div></td> </tr> <tr><Td></Td> <Td valign="top" height="35px" class="help">Image maximum size <b>400 </b>kb</span></Td> </tr> <tr><Td></Td><Td valign="top" height="35px"><input type="submit" id="mybut" value=" Upload " name="Submit"/></Td></tr> <tr> <td width="200"> </td> <td width="200"><table width="200" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="200" align="center"><div align="left"></div></td> <td width="100"> </td> </tr> </table></td> </tr> </table> </form> </div> </td> </tr> </tbody> </table> </div> </div> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1269229 Share on other sites More sharing options...
jacko_162 Posted September 14, 2011 Author Share Posted September 14, 2011 works a treat, now how do i get the rename sorted how i had on my old code above into this one? //Assign Random number & the member_id from session $rand = mt_rand(1,9999999); $member_id = $_SESSION['SESS_MEMBER_ID']; //Rename the file for example "85674_1.jpg" $newFileName = $rand . "_" . $member_id.$ext; my current working code: <?php session_start(); include('Includes/auth.php'); require_once('header.php'); error_reporting(0); $change=""; $abc=""; $rand = mt_rand(1,9999999); $member_id = $_SESSION['SESS_MEMBER_ID']; define ("MAX_SIZE","950"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if($_SERVER["REQUEST_METHOD"] == "POST") { $image =$_FILES["file"]["name"]; $uploadedfile = $_FILES['file']['tmp_name']; $caption = $_POST["caption"]; if ($image) { $filename = stripslashes($_FILES['file']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { $change='<div class="notification attention png_bg"> <a href="#" class="close"><img src="img/cross_grey_small.png" title="Close this notification" alt="close" /></a> <div>Unknown Image extension<br> </div> </div> '; $errors=1; } else { $size=filesize($_FILES['file']['tmp_name']); if ($size > MAX_SIZE*1024) { $change='<div class="notification attention png_bg"> <a href="#" class="close"><img src="img/cross_grey_small.png" title="Close this notification" alt="close" /></a> <div>You have exceeded the size limit!<br> </div> </div> '; $errors=1; } if($extension=="jpg" || $extension=="jpeg" ) { $uploadedfile = $_FILES['file']['tmp_name']; $src = imagecreatefromjpeg($uploadedfile); } else if($extension=="png") { $uploadedfile = $_FILES['file']['tmp_name']; $src = imagecreatefrompng($uploadedfile); } else { $src = imagecreatefromgif($uploadedfile); } echo $scr; list($width,$height)=getimagesize($uploadedfile); $newwidth=650; $newheight=($height/$width)*$newwidth; $tmp=imagecreatetruecolor($newwidth,$newheight); $newwidth1=150; $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 = "gallery/". $_FILES['file']['name']; $filename1 = "gallery/thumb/small". $_FILES['file']['name']; imagejpeg($tmp,$filename,100); imagejpeg($tmp1,$filename1,100); imagedestroy($src); imagedestroy($tmp); imagedestroy($tmp1); }} } //If no errors registred, print the success message if(isset($_POST['Submit']) && !$errors) { $result = mysql_query("INSERT INTO `gallery` (`image`, `thumb`,`memberid`, `caption`) VALUES ('$filename', '$filename1', '$member_id', '$caption')") or die (mysql_error()); $change=' <div class="notification success png_bg"> <a href="#" class="close"><img src="img/cross_grey_small.png" title="Close this notification" alt="close" /></a> <div>Image Uploaded Successfully!<br> </div> </div>'; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf8"/> <title>Index</title> </head> <body class="cloudy"> <table width="80%" border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td width="40%" valign="top"> <div align="right"><a href="account.php"><img src="img/buttons/my_account.png" alt="" border="0" /></a><img src="img/spacer.png" alt="" width="10" height="1" /><a href="gallery.php"><img src="img/buttons/my_gallery.png" alt="" border="0" /></a><img src="img/spacer.png" alt="" width="10" height="1" border="0" /></div> <div class="content-box"> <div class="content-box-header"> <h3>Add Gallery Photo</h3> </div> <div class="content-box-content"> <div> <table width="100%" border="0" cellspacing="0" cellpadding="6"> <tr> <td colspan="7" valign="top"> <form method="post" action="" enctype="multipart/form-data" name="form1"> <table border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="2"><?php echo $change; ?></td> </tr> <tr> <td>Picture: </td> <td> <div align="left"> <input size="25" name="file" type="file"/> </div></td> </tr> <tr><td></td> <td>Image maximum size <b>950 </b>kb</span></td> </tr> <tr> <td>Caption: </td> <td><input class="text" name="caption" type="text" value="" /></td> </tr> <tr><td></td><td><input type="submit" id="mybut" value=" Upload " name="Submit"/></td></tr> <tr> <td> </td> <td> </td> </tr> </table> </form> </td> </tr> </table> </p> </div> </div> </td> </tr> </table> <?php require_once('footer.php'); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1269250 Share on other sites More sharing options...
jacko_162 Posted September 14, 2011 Author Share Posted September 14, 2011 voip03 thank you for the help and the code snippets, between yours and mine i managed to acomplish my need perfectly. although when i upload a transparent PNG it adds a black background, but tbh i can prob live with it. Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1269255 Share on other sites More sharing options...
voip03 Posted September 14, 2011 Share Posted September 14, 2011 although when i upload a transparent PNG it adds a black background, but tbh i can prob live with it. can you CSS? Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1269263 Share on other sites More sharing options...
jacko_162 Posted September 14, 2011 Author Share Posted September 14, 2011 yes Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1269274 Share on other sites More sharing options...
voip03 Posted September 14, 2011 Share Posted September 14, 2011 CSS wiil do the job, If you have problem let me know. good luck Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1269278 Share on other sites More sharing options...
jcbones Posted September 15, 2011 Share Posted September 15, 2011 The reason you get a black background is that jpeg doesn't support transparent images like PNG does. You are making all of your images jpg's with the latest code. SimpleImage is a great class and I have used it before. Your code only needed one line changed to make it work. <?php //this line: //Try to upload it. if(!move_uploaded_file($_FILES['uploaded']['tmp_name'], $newfilename)) //to this line: //Try to upload it. if(!$image->save($newfilename,$image->image_type)) Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1269421 Share on other sites More sharing options...
voip03 Posted September 15, 2011 Share Posted September 15, 2011 The reason you get a black background is that jpeg doesn't support transparent images like PNG does. You are making all of your images jpg's with the latest code. SimpleImage is a great class and I have used it before. Your code only needed one line changed to make it work. <?php //this line: //Try to upload it. if(!move_uploaded_file($_FILES['uploaded']['tmp_name'], $newfilename)) //to this line: //Try to upload it. if(!$image->save($newfilename,$image->image_type)) Thank you Quote Link to comment https://forums.phpfreaks.com/topic/247084-upload-image-form-image-resize/#findComment-1269529 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.