redelcare problem - image uploader / resizer

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
Blaydo
Forum Newbie
Posts: 14
Joined: Fri Jun 06, 2003 4:31 pm
Location: Michigan, USA
Contact:

redelcare problem - image uploader / resizer

Post by Blaydo »

Hey guys its me, i'm back lol.

Heres whats up, i submit a form from "form.php" to this php document, and it grabs the files and uploads them to the server, and i want it to create thumbnails of all of the uploaded files, and display them into a printed table.

this is where i'm stuck:

Code: Select all

<?php
if($uploads <= 1) 
{ 
    $uploads = 5; 
} 
$fields = $uploads + $uploads; 

for($n = 0; $n < $uploads; $n++) 
{ 
    if($uploadedFile[$n] != "" && $uploadedFile[$n] != "none") 
    { 

    copy("$uploadedFile[$n]", "$path$uploadedFile_name[$n]"); 
    rename("$path$uploadedFile_name[$n]", "$path$name$var1$uploadedFile_name[$n]"); 
    if(file_exists("$path$name$var1$uploadedFile_name[$n]")) 
    { 
function thumbnail($i,$nw,$p,$nn) { 
    $img=imagecreatefromjpeg("$i"); 
    $ow=imagesx($img); 
    $oh=imagesy($img); 
    $scale=$nw/$ow; 
    $nh=ceil($oh*$scale); 
    $newimg=imagecreate($nw,$nh); 
    imagecopyresized($newimg,$img,0,0,0,0,$nw,$nh,$ow,$oh); 
    imagejpeg($newimg, $p.$nn); 
    return true; 
} 

#thumbnail(filetouse,newwidth,newpath,newname); 
thumbnail("$path$name$var1$uploadedFile_name[$n]",68,"/home/doc/public_html/tom/form1/tmp/thmb/","$thumb$name$var1$uploadedFile_name[$n]");	

        print("upload successful for $name$var1$uploadedFile_name[$n] - $uploadedFile_size[$n] bytes<br>\n"); 
		print("<a href="$balls$name$var1$uploadedFile_name[$n]">$uploadedFile_name[$n]</a><br><br>\n"); 
		print("<a href="$nipples$thumb$name$var1$uploadedFile_name[$n]">thumbnail_$uploadedFile_name[$n]</a><br><br>\n"); 
		print("<table width="300" border="1" cellspacing="0" cellpadding="0" bordercolor="#999999">\n");
        print("<tr align="center" valign="middle">\n");
        print("<td width="70" height="70"><a href="$balls$name$var1$uploadedFile_name[$n]" target="_blank" ><img src="$nipples$thumb$name$var1$uploadedFile_name[$n]" border="0"></a></td>\n");
        print("<td width="70" height="70">t2</td>\n");
        print("<td width="70" height="70">t3</td>\n");
        print("<td width="70" height="70">t4</td>\n");
        print("<td width="70" height="70">t5</td></tr>\n");
        print("<tr align="center" valign="middle">\n");
        print("<td width="70" height="70">t6</td>\n");
        print("<td width="70" height="70">t7</td>\n");
        print("<td width="70" height="70">t8</td>\n");
        print("<td width="70" height="70">t9</td>\n");
        print("<td width="70" height="70">t10</td></tr>\n");
        print("<tr align="center" valign="middle">\n");
        print("<td width="70" height="70">t11</td>\n");
        print("<td width="70" height="70">t12</td>\n");
        print("<td width="70" height="70">t13</td>\n");
        print("<td width="70" height="70">t14</td>\n");
        print("<td width="70" height="70">t15</td></tr>\n");
        print("<tr align="center" valign="middle"> \n");
        print("<td width="70" height="70">t16</td>\n");
        print("<td width="70" height="70">t17</td>\n");
        print("<td width="70" height="70">t18</td>\n");
        print("<td width="70" height="70">t19</td>\n");
        print("<td width="70" height="70">t20</td></tr></table>\n");
        } 
    else
    { 
        print("error: upload failed<br>\n"); 
    } 
    } 
} 
?>



?>
It works fine for only one image, and displays it correctly. but as soon as i do multiple images, it cant make the thumbs... any ideas?
Blaydo
Forum Newbie
Posts: 14
Joined: Fri Jun 06, 2003 4:31 pm
Location: Michigan, USA
Contact:

Post by Blaydo »

this is the error message i get:

Fatal error: Cannot redeclare thumbnail() (previously declared in /home/doc/public_html/tom/form1/thumbtest.php:57) in /home/doc/public_html/tom/form1/thumbtest.php on line 57
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

You're looping around $uploads with a method bang in the middle of the for loop.

Move this:

Code: Select all

function thumbnail($i,$nw,$p,$nn) { 
    $img=imagecreatefromjpeg("$i"); 
    $ow=imagesx($img); 
    $oh=imagesy($img); 
    $scale=$nw/$ow; 
    $nh=ceil($oh*$scale); 
    $newimg=imagecreate($nw,$nh); 
    imagecopyresized($newimg,$img,0,0,0,0,$nw,$nh,$ow,$oh); 
    imagejpeg($newimg, $p.$nn); 
    return true; 
}
Outside the for loop.

Regards,
Blaydo
Forum Newbie
Posts: 14
Joined: Fri Jun 06, 2003 4:31 pm
Location: Michigan, USA
Contact:

Post by Blaydo »

thank you very much, now it works.

you guys are probably laughing but i'm catching on :)
Post Reply