Altering code to add a second image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jwd
Forum Newbie
Posts: 3
Joined: Tue Dec 16, 2008 4:18 pm

Altering code to add a second image

Post by jwd »

Hope someone can take a quick glance and guide me to what I'm doing wrong.

Basically, I have a script that let's me upload 1 image... which I want it to upload 2. But it stalls out everytime after uploading the first image.

Below if the original code, then mine (I put my changes in bold red). I really would greatly appreciate any advise anyone could provide.

I'm certainly not try to freeload for advice, I'd like to learn what I'm doing wrong if anyone would be kind enough to help me out!

THANKS!

ORIGINAL:

Code: Select all

<?
include ("define.php");
include ("func.php");
$subject=addslashes($subject);
 
$date=date("Y-m-d H:i:s");
 
 
        $ph=date("his").$_FILES['photo1']['name'];
        $fileName=$_FILES['photo1']['name'];
        $ext = substr($fileName, strrpos($fileName, '.') + 1);
        if(($ext!="php") and  ($ext!="html") and ($ext!="htm"))
        
        @move_uploaded_file($_FILES['photo1']['tmp_name'], "./photos/".$ph);
        if(!empty($_FILES['photo1']['name']))
{       $image="./photos/".$ph ;
 
$newfilename="./photos/".$ph;
$thumbname="./photos/thumb_".$ph;
 
            switch($_FILES["photo1"]['type'])
             {
                 case 'image/jpeg':
                 case 'image/pjpeg':
                    createthumbnailjpg($newfilename,$thumbname,175,0);
                 break;
                 case 'image/png':
                 case 'image/x-png':
                     createthumbnailpng($newfilename,$thumbname, 175,0);
                     
                 break;
                 case 'image/gif':
                     createthumbnailgif($newfilename,$thumbname, 175,0);
                     
                 break;
}
}
        $ph=date("his").$_FILES['doc1']['name'];
        $fileName=$_FILES['doc1']['name'];
        $ext = substr($fileName, strrpos($fileName, '.') + 1);
        if(($ext!="php") )
        
        @move_uploaded_file($_FILES['doc1']['tmp_name'], "./docs/".$ph);
        if(!empty($_FILES['doc1']['name']))
        $doc="./docs/".$ph ;
 
$sql="select id from inputinfo";
$rez=mysql_query($sql,$dblnk);
$nr=mysql_num_rows($rez);
$nr++;
 
$sql="insert into inputinfo(subject,`description`,document,image,date_submitted,thumb,category,rank) values('$subject','$area2','$doc','$image','$date','$thumbname','$category','$nr')";
$rez=mysql_query($sql,$dblnk);
 
header('location: output.php');
?>

MY CHANGES (IN BOLD RED):

Code: Select all

<?
include ("define.php");
include ("func.php");
$subject=addslashes($subject);
 
$date=date("Y-m-d H:i:s");
 
 
        $ph=date("his").$_FILES['photo1']['name'];
        $fileName=$_FILES['photo1']['name'];
        $ext = substr($fileName, strrpos($fileName, '.') + 1);
        if(($ext!="php") and  ($ext!="html") and ($ext!="htm"))
        
        @move_uploaded_file($_FILES['photo1']['tmp_name'], "./photos/".$ph);
        if(!empty($_FILES['photo1']['name']))
{       $image="./photos/".$ph ;
 
$newfilename="./photos/".$ph;
$thumbname="./photos/thumb_".$ph;
 
            switch($_FILES["photo1"]['type'])
             {
                 case 'image/jpeg':
                 case 'image/pjpeg':
                    createthumbnailjpg($newfilename,$thumbname,175,0);
                 break;
                 case 'image/png':
                 case 'image/x-png':
                     createthumbnailpng($newfilename,$thumbname, 175,0);
                     
                 break;
                 case 'image/gif':
                     createthumbnailgif($newfilename,$thumbname, 175,0);
                     
                 break;
}
}
 
 
[color=#FF0000][b]$ph=date("his").$_FILES['photo2']['name'];
        $fileName=$_FILES['photo2']['name'];
        $ext = substr($fileName, strrpos($fileName, '.') + 1);
        if(($ext!="php") and  ($ext!="html") and ($ext!="htm"))
        
        @move_uploaded_file($_FILES['photo2']['tmp_name'], "./photos/".$ph);
        if(!empty($_FILES['photo2']['name']))
{       $image="./photos/".$ph ;
 
$newfilename="./photos/".$ph;
$thumbname="./photos/thumb_".$ph;
 
            switch($_FILES["photo2"]['type'])
             {
                 case 'image/jpeg':
                 case 'image/pjpeg':
                    createthumbnailjpg($newfilename,$thumbname2,175,0);
                 break;
                 case 'image/png':
                 case 'image/x-png':
                     createthumbnailpng($newfilename,$thumbname2, 175,0);
                     
                 break;
                 case 'image/gif':
                     createthumbnailgif($newfilename,$thumbname2, 175,0);
                     
                 break;
}
}[/b][/color]
 
 
        $ph=date("his").$_FILES['doc1']['name'];
        $fileName=$_FILES['doc1']['name'];
        $ext = substr($fileName, strrpos($fileName, '.') + 1);
        if(($ext!="php") )
        
        @move_uploaded_file($_FILES['doc1']['tmp_name'], "./docs/".$ph);
        if(!empty($_FILES['doc1']['name']))
        $doc="./docs/".$ph ;
 
$sql="select id from inputinfo";
$rez=mysql_query($sql,$dblnk);
$nr=mysql_num_rows($rez);
$nr++;
 
$sql="insert into inputinfo(subject,`description`,document,image,[b][color=#FF0000]image2[/color][/b],date_submitted,thumb,[color=#FF0000][b]thumb2,[/b][/color]category,rank) values('$subject','$area2','$doc','$image','$date','$thumbname',[color=#FF0000][b]'$thumbname2'[/b][/color],'$category','$nr')";
$rez=mysql_query($sql,$dblnk);
 
header('location: output.php');
?>
Thanks.
Post Reply