Jump to content

Upload image form (Image Resize)


jacko_162

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
   }      

}
?>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.