0

Hello, I've got this code for my pictures when they are being uploaded, but I have a problem. I want to be able to create a thumbnail with the size 125*180 for every picture and name them their filename but like this "thumb_filename.jpg" etc.

I have searched on google and found some scripts but I don't seem to be able to implement it with my script. Could anybody be very kind and help me with this as I am kinda new to PHP and I have been looking for answers for weeks :)

$filename[0];$filename[1];$filename[2];$filename[3];$filename[4];$filename[5];
for($i = 0; $i < $images; $i++)
{
$saveFolder = "uploads/theBulletin/products/";
if ((($_FILES["file".$i]["type"] == "image/gif")
|| ($_FILES["file".$i]["type"] == "image/jpeg")
|| ($_FILES["file".$i]["type"] == "image/pjpeg")
|| ($_FILES["file".$i]["type"] == "image/png")
|| ($_FILES["file".$i]["type"] == "image/bmp")))
{
$ext;									if($_FILES["file".$i]["type"] == "image/gif"){ $ext = "gif";}
else if(($_FILES["file".$i]["type"] == "image/jpeg") || ($_FILES["file".$i]["type"] == "image/pjpeg")){ $ext = "jpg";}
else if($_FILES["file".$i]["type"] == "image/png"){ $ext = "png";}
else if($_FILES["file".$i]["type"] == "image/png"){ $ext = "bmp";}
$filename[$i] = rand().rand().rand().rand().rand().rand().".".$ext;
if ($_FILES["file".$i]["error"] > 0){}
else
{
if (file_exists($saveFolder . $filename[$i]))
{
}
else
{
move_uploaded_file($_FILES["file".$i]["tmp_name"],$saveFolder . $filename[$i]);
}
}
}
}

Thanks in advance
Regards,
Mike

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by muralikalpana
0

use this for image upload. create partners_logs folder with in that create croping image folder(265x150)

<?
    if(is_uploaded_file($_FILES["pimage"]["tmp_name"])!='')
            {
            //echo"file in";exit;
            //echo"in ";exit;
            $rand_variable1=rand(10000,100000);
            if(is_uploaded_file($_FILES["pimage"]["tmp_name"]))
            {
               if($hidden_image!="")
               {
 
               @unlink("partners_logs/".$hidden_image);
                @unlink("partners_logs/250x150/".$hidden_image);
 
               }
            $file_image13=$rand_variable1.$_FILES["pimage"]["name"];
            move_uploaded_file($_FILES["pimage"]["tmp_name"], "partners_logs/".$file_image13);
 
                $Attachments3=$file_image13;
 
            }
            /************************************Resizing the image 80*60****************/
            $path3="partners_logs";
            $filetype3=$_FILES["pimage"]["type"];
            $bgim_file_name = $path3."/".$Attachments3; 
            $bgimage_attribs = getimagesize($bgim_file_name);
 
            if($filetype3=='image/gif')    
                {
                    $bgim_old = imagecreatefromgif($bgim_file_name); 
                }    
            else if(($filetype3=='image/pjpeg') || ($filetype3=='image/jpeg'))    
                {
                     $bgim_old = imagecreatefromjpeg($bgim_file_name);
                }
              else    if(($filetype3=='image/png') || ($filetype3=='image/x-png'))
                {
                     $bgim_old = imagecreatefrompng($bgim_file_name);
                     imageAlphaBlending($bgim_old, true);
imageSaveAlpha($bgim_old, true);
                }
 
            $bgth_max_width =265; //for Album image
            $bgth_max_height =150;
            $bgratio = ($bgwidth > $bgheight) ? $bgth_max_width/$bgimage_attribs[0] : $bgth_max_height/$bgimage_attribs[1];
 
            $bgth_width =265;//$image_attribs[0] * $ratio; 
            $bgth_height =150;//$image_attribs[1] * $ratio;
 
            $bgim_new = imagecreatetruecolor($bgth_width,$bgth_height); 
            imageantialias($bgim_new,true); 
            $bgth_file_name = "partners_logs/250x150/$Attachments3";
            imagecopyresampled($bgim_new,$bgim_old,0,0,0,0,$bgth_width,$bgth_height, $bgimage_attribs[0], $bgimage_attribs[1]);
            if($filetype3=='image/gif')    
                {
                    imagegif($bgim_new,$bgth_file_name,100);
                    //$bgim_old = imagegif($bgim_file_name); 
                }    
            else if(($filetype3=='image/pjpeg') || ($filetype3=='image/jpeg'))    
                {
                     imagejpeg($bgim_new,$bgth_file_name,100);
                }
              else    if(($filetype3=='image/png') || ($filetype3=='image/x-png'))
                {
                     imagepng($bgim_new,$bgth_file_name,9);
                       //set the background color to your choice, paramters are int values of red,green and blue  
imagecolorallocate($bgim_new,0xFF,0xFF,0xFF);
                }                
            /************End Resize of 80*60*******************/
 
            }
         else
        {
        //echo"file out";exit;
        $Attachments3=$hidden_image;
        }
?>
<!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>Untitled Document</title>
</head>
 
<body>
<form name="UserDetails" action="" method="post"  enctype="multipart/form-data" onSubmit="return checkValid(this);">
            <input type="hidden" name="new_action" value="<?=$act?>">
            <input type="hidden" name="new_start" value="<?=$start?>">
            <? if($act == 'edit'){
               $qUsers   = "SELECT * FROM partners WHERE auto_id = $id";
               $rsUsers  = getSqlQuery($qUsers);
               $resUsers = getSqlFetch($rsUsers);
               extract($resUsers);
            ?>
            <input type="hidden" name="edit_id" value="<?=$id?>">
            <? }?>
            <table width="50%"  border="0" cellspacing="0" cellpadding="4">
            <? if($errMsg == 1){?>
            <tr align="center">
              <td colspan="5" align="center" valign="middle"><FONT color=red>Admin Name already exist! Please try again.</FONT></td>
            </tr>
            <? }?>
 
 
 
            <tr align="center">
              <td>&nbsp;</td>
              <td align="left">Company Logo</td>
              <td><strong>:</strong></td>
              <td align="left"><input type="file" name="pimage" >
               <input type="hidden" name="hidden_image" value="<?php echo $images ?>" ></td>
              <td>&nbsp;</td>
            </tr>
           
 
 
            <tr align="center">
              <td width="5%" height="1">&nbsp;</td>
              <td width="29%" height="1" align="left">&nbsp;</td>
              <td width="3%" height="1">&nbsp;</td>
              <td width="58%" height="1">&nbsp;</td>
              <td width="5%" height="1">&nbsp;</td>
            </tr>
            <tr>
              <td height="20" colspan="4" align="right">
              <input type="submit" name=submit value="submit">
                            <!--<input name="Submit" type="submit" class="but" id="Submit" value="Submit">-->
                <!--<input name="Reset" type="reset" class="but" id="Submit" value="Reset">-->
 
              <!--<input name="Button" type="button" class="but" id="Submit" value="Cancel" onClick="history.back();">-->                </td>
              <td height="20" align="right">&nbsp;</td>
            </tr>
        </table>
        </form>
</body>
</html>

Edited by muralikalpana: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.