Link to home
Start Free TrialLog in
Avatar of asmaameercp
asmaameercp

asked on

How to upload image with type Tiff image using GD

Hello Pals,

I can upload images with all format like Jpeg,png , gif but i cannot
do same in case of tiff image . How it can possible . I give
my Code of upload image below.

please Refer and help me

Regards
Anes P.A
<?php session_start();
if(!isset($_SESSION['user']))
{
 $_SESSION['non-allowed'] = "YES";
 header('location: index.php');
}
require("db/config.inc.php"); 
// pull in the file with the database class 
require("db/Database.class.php"); 
// create the $db object 
$db = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
// connect to the server 
$db->connect(); 
include('functions/functions.php');
if(isset($_POST['description']))
{
$myimage = $_FILES['datafile'];
$title = mysql_real_escape_string($_POST['title']);
$videoUrl = mysql_real_escape_string($_POST['videoUrl']);
$description = mysql_real_escape_string($_POST['description']);
//print_r($myimage);
$j = 0;
$z = 0;
$LENGTH = count($myimage['name']);
for($i=0;$i<$LENGTH;$i++)
{
if($myimage['name'][$i]!="")
{
$ARR[$j] =  $myimage['name'][$i];
$j++;
}
}
//Attributes used For Real Upload Process
for($m=0;$m<$LENGTH;$m++)
{
if($myimage['name'][$m]!="")
{
$UPLOAD['name'][$z] =  $myimage['name'][$z];
$UPLOAD['tmp_name'][$z] = $myimage['tmp_name'][$z];
$z++;
}
}
$newlength = count($ARR);
for($k=0;$k<$newlength;$k++)
{
$extension = getExtension($ARR[$k]);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension !=  
"png") && ($extension != "gif")) 
 		{
	 			$errors[$k]=1;
 		}
}
//echo "ddfdfd <br>";
//print_r($errors);
if(count($errors)==1)
{
  $Error = "Upload all images with valid extension(jpg,jpeg,png,gif)";
}
else
{
//INSERT data into tbl_posts Table
$sql = "INSERT INTO tbl_posts (title,description,videoUrl)  
VALUES('$title','$description','$videoUrl')";
$result = mysql_query($sql) or die(mysql_error());
$ID = mysql_insert_id();
//start upload process
for($v=0;$v<$newlength;$v++)
{
$target_path = "uploads/";
 $tempFile = $UPLOAD['tmp_name'][$v];
$name = rand(5,750000).basename($UPLOAD['name'][$v]);
//save name to insert in database
$NAME[$v] = $name; 
$target_path = $target_path.$name; 
 move_uploaded_file($tempFile,$target_path);
}
$namlength = count($NAME);
// Thumb nail Creation part
for($n=0;$n<$namlength;$n++)
{
//echo "Sajdfidfidfi".$NAME[$n];
 $targetFile = "uploads/".$NAME[$n];
 $large = $NAME[$n];
 $small = $NAME[$n];	
$sql1 = "INSERT INTO tbl_photos (postId,large,small)  
VALUES($ID,'$large','$small')";
$result1 = mysql_query($sql1) or die(mysql_error());
 //echo "sssdsdsdsds".$targetFile;
 $target_path = "uploads/";
$imgsize = @getimagesize($targetFile);
switch(strtolower(substr($targetFile, -3))){
    case "jpg":
        $image = imagecreatefromjpeg($targetFile);    
    break;
	 case "jpeg":
        $image = imagecreatefromjpeg($targetFile);    
    break;
    case "png":
        $image = imagecreatefrompng($targetFile);
    break;
    case "gif":
        $image = imagecreatefromgif($targetFile);
    break;
    default:
        exit;
    break;
} 
$width = 80; //New width of image    
//$height = $imgsize[1]/$imgsize[0]*$width; //This maintains  
proportions
$height = 53;
$src_w = $imgsize[0];
$src_h = $imgsize[1];
$picture = imagecreatetruecolor($width, $height);
imagealphablending($picture, false);
imagesavealpha($picture, true);
$bool = imagecopyresampled($picture, $image, 0, 0, 0, 0, $width,  
$height, $src_w, $src_h);  
if($bool){
    switch(strtolower(substr($targetFile, -3))){
        case "jpg":
           // header("Content-Type: image/jpeg");
            $bool2 =  
imagejpeg($picture,$target_path."thumbs/".$NAME[$n],80);
        break;
        case "png":
            //header("Content-Type: image/png");
            imagepng($picture,$target_path."thumbs/".$NAME[$n]);
        break;
        case "gif":
            //header("Content-Type: image/gif");
            imagegif($picture,$target_path."thumbs/".$NAME[$n]);
        break;
    }
}
//imagedestroy($picture);
//imagedestroy($image);
//$Error = "Successfully Save Data";
for($v=0;$v<$newlength;$v++)
{
$target_path = "uploads/";
// $tempFile = $UPLOAD['tmp_name'][$v];
//save name to insert in database
$name = $NAME[$v];
$target_path = $target_path.$name; 
 //Watermark main file
 $watermarkfile = "images/water-mark.png";
 watermark($target_path, $watermarkfile, $target_path); 
}
header('location: postDetails.php?p=success'); 
}
}
} 
 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;  
charset=iso-8859-1" />
<title>Add Post Page</title>
<script language="JavaScript" src="../js/validations.js"></script>
<link href="../css/styles.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
	background-image: url(../images/bg.jpg);
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.style1 {color: #FFFFFF}
-->
</style></head> 
<body>
<table width="980" border="0" align="center" cellpadding="0"  
cellspacing="0" class="main_table_border">
  <tr>
    <td><table width="980" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><img src="../images/admin_banner.jpg" width="980"  
height="146" /></td>
      </tr>
      <tr>
        <td><!-- menu start-->
              <table width="980" border="0" cellspacing="0"  
cellpadding="0">
                <tr>
                  <td height="62" align="left" valign="top"  
class="admin_menu_bg">Add New Post </td>
                </tr>
              </table>
          <!-- menu end -->
        </td>
      </tr>
      <tr>
        <td align="center"><!-- welcome section start -->
              <!-- welcome section end --></td>
      </tr>
      <tr>
        <td height="10px;"></td>
      </tr>
      <tr> 
        
 
	  
	  <td align="center" valign="top"><table width="100%"  
border="0" cellspacing="10" cellpadding="0">
          <tr> 
            <td height="542" align="center" valign="top"><table  
width="100%" border="0" cellspacing="10" cellpadding="0">
          <tr>
            <td width="22%" align="left" valign="top"><table  
width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td class="normal_text style1" height="25"  
bgcolor="#090909">Navigation Links</td>
              </tr>
              <tr>
                <td height="23" class="normal_text"><a  
href="postDetails.php" class="normal_text">Post Details </a></td>
              </tr>
              <tr>
                <td height="1" colspan="5" align="left"  
bgcolor="#999999" class="normal_text"></td>
              </tr>
              <tr>
                <td height="23" class="normal_text"><a href="#"  
class="normal_text"> Pending Post Images </a></td>
              </tr>
              <tr>
               <td height="1" colspan="5" align="left"  
bgcolor="#999999" class="normal_text"></td>
              </tr>
              <tr>
                <td height="23" class="normal_text"><a  
href="logout.php" class="normal_text"> Logout </a></td>
              </tr> 
              <tr>
                <td>&nbsp;</td>
              </tr>
            </table></td>
	    
	  
	  
	  
	  
	  
	  
	  
	  
        <td align="left" valign="top"><form id="postAdd"  
name="postAdd" method="post" onsubmit ="return validate(this);"  
enctype="multipart/form-data">
          <table width="50%" border="0" cellspacing="5"  
cellpadding="0">
		  <tr>
		  <td colspan="2"><div align="center" class="username"  
id="Error" style="float:left;width:200px;font-family:Arial, Helvetica,  
sans-serif; font-size:13px;margin-bottom:6px; text-align:center;  
color:#FF0000;padding-left: 58px;font-weight: bold"></div>
</td>
		  
		  </tr>
		  
            <tr>
              <td width="19%" align="left"  
class="normal_text">Title:</td>
              <td width="81%" align="left"><input name="title"  
id="title" type="text" class="field" value=<?php print($title);  
?>/></td>
            </tr>
            <tr>
              <td align="left" class="normal_text">Video URL:</td>
              <td align="left"><input name="videoUrl" id="videoUrl"  
type="text" class="field"  value="<?php print($videoUrl); ?>"/>
             
              </td>
            </tr>
            <tr>
              <td align="left" class="normal_text">Photo:</td>
              <td align="left"><table width="100%" border="0"  
cellspacing="0" cellpadding="0">
                <tr>
                  <td width="64%"><input type="file" name="datafile[]"  
id="datafile[]" /></td>
                  <td width="36%">&nbsp;</td>
                </tr>
				 <tr>
                  <td width="64%"><input type="file" name="datafile[]"  
id="datafile[]" /></td>
                  <td width="36%">&nbsp;</td>
                </tr>
				 <tr>
                  <td width="64%"><input type="file" name="datafile[]"  
id="datafile[]" /></td>
                  <td width="36%">&nbsp;</td>
                </tr>
				 <tr>
                  <td width="64%"><input type="file" name="datafile[]"  
id="datafile[]" /></td>
                  <td width="36%">&nbsp;</td>
                </tr>
				 <tr>
                  <td width="64%"><input type="file" name="datafile[]"  
id="datafile[]" /></td>
                  <td width="36%">&nbsp;</td>
                </tr>
				 <tr>
                  <td width="64%"><input type="file" name="datafile[]"  
id="datafile[]" /></td>
                  <td width="36%">&nbsp;</td>
                </tr>
				 <tr>
                  <td width="64%"><input type="file" name="datafile[]"  
id="datafile[]" /></td>
                  <td width="36%">&nbsp;</td>
                </tr>
				 <tr>
                  <td width="64%"><input type="file" name="datafile[]"  
id="datafile[]" /></td>
                  <td width="36%">&nbsp;</td>
                </tr>
				
				
				
              </table></td>
            </tr>
            
            <tr>
              <td align="left" class="normal_text">Description</td>
              <td align="left"><textarea name="description"  
id="description" rows="6" class="field"><?php print($description);  
?></textarea></td>
            </tr>
            <tr>
              <td align="left" class="normal_text">&nbsp;</td>
              <td align="left"><table width="100%" border="0"  
cellspacing="0" cellpadding="0">
                <tr>
                  <td width="18%"><input type="submit" name="submit"  
value="Add Post" /></td>
                  <td width="82%"><input type="reset" name="Submit2"  
value="Reset" /></td>
                </tr>
              </table></td>
            </tr>
          </table>
        </form></td>
      </tr> 
 
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="50" colspan="2" align="center" valign="middle"  
bgcolor="#080904"><table width="95%" border="0" cellspacing="0"  
cellpadding="0">
          <tr>
            <td width="52%" align="left" valign="middle"  
class="footer_text"><a href="#" class="footer_text">Home</a> | <a  
href="#" class="footer_text">Members Entrance</a> | <a href="#"  
class="footer_text">About Us</a> | <a href="#"  
class="footer_text">Services</a> | <a href="#" class="footer_text">All  
Episodes</a> | <a href="#" class="footer_text">Contact Us</a> | <a  
href="#" class="footer_text">Terms</a></td>
            <td width="48%" align="right" valign="middle"  
class="footer_text">(C)Copyright 2002-2009 www.homelesshomies.com. All  
rights reserved. </td>
          </tr>
          <tr>
            <td height="25" colspan="2" align="right" valign="middle"  
class="footer_text">Site Designed and Developed By <a  
href="htttp://www.pioneeroutsourcing.com" target="_blank"  
class="footer_text">www.pioneeroutsourcing.com</a></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td height="5px;"></td>
      </tr>
    </table></td>
  </tr>
</table>
</table>
</table>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of pg-expert
pg-expert
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial