confused again
03-21-2005, 06:56 PM
Well, this is hard to explain but i've tried for hours to get this simple thing to work.
I'm trying to resize images, this is the code i've come up with:
$imagesize = getimagesize("$files[$i]['name']");
$origwidth=$imagesize[0];
$origheight=$imagesize[1];
$maxwidth="100";
if ($origwidth>$maxwidth) {
$percent=$maxwidth/$origwidth;
$new_height=$origheight*$percent;
$new_width=$maxwidth;
} else {
$new_height=$origheight;
$new_width=$origwidth;
}
Now here is the code that prints each image out thats in the directory.
for ($i = 1; $i <= $filecounter; $i++) {
$allowed_prefix = $userid_log . '_';
$len = strlen($allowed_prefix);
if (substr($files[$i]['name'], 0, $len) == $allowed_prefix) {
$fileoutput.='<table border="1" cellpadding="10" cellspacing="0" width="95%" bordercolor="#000000" bgcolor="#A4B2C8">';
$fileoutput.='<tr>';
$fileoutput.=' <td width="30"><input type="checkbox" name="file[]" value="'.$files[$i]['name'].'"></td>';
$fileoutput.=' <td width="100"><img src="../../pics/'.$files[$i]['name'].'" width="'.$new_width.'" height="'.$new_height.'"></td>';
$fileoutput.=' <td>'.$files[$i]['name'].'</td>';
$fileoutput.=' <td width="100">'.$files[$i]['size'].'</td>';
$fileoutput.='</font></td></tr>';
$fileoutput.='</table><p>';
}
}
And here is the code that determines what $files[$i]['name'] is:
if ($dh = opendir($dir)) {
$dircount=0;
$filecount=0;
while (($file = readdir($dh)) !== false) {
if(filetype($dir.$file)=="dir"){
$dircount++;
if($dircount > 2){
$dir_names[$dircount-2] = $file;
}
} else {
$filecount++;
$files[$filecount]['name'] = $file;
}
The problem is, the image script isn't determining the dimentions for each individual image, and i'm not sure how to fix this..
I'm trying to resize images, this is the code i've come up with:
$imagesize = getimagesize("$files[$i]['name']");
$origwidth=$imagesize[0];
$origheight=$imagesize[1];
$maxwidth="100";
if ($origwidth>$maxwidth) {
$percent=$maxwidth/$origwidth;
$new_height=$origheight*$percent;
$new_width=$maxwidth;
} else {
$new_height=$origheight;
$new_width=$origwidth;
}
Now here is the code that prints each image out thats in the directory.
for ($i = 1; $i <= $filecounter; $i++) {
$allowed_prefix = $userid_log . '_';
$len = strlen($allowed_prefix);
if (substr($files[$i]['name'], 0, $len) == $allowed_prefix) {
$fileoutput.='<table border="1" cellpadding="10" cellspacing="0" width="95%" bordercolor="#000000" bgcolor="#A4B2C8">';
$fileoutput.='<tr>';
$fileoutput.=' <td width="30"><input type="checkbox" name="file[]" value="'.$files[$i]['name'].'"></td>';
$fileoutput.=' <td width="100"><img src="../../pics/'.$files[$i]['name'].'" width="'.$new_width.'" height="'.$new_height.'"></td>';
$fileoutput.=' <td>'.$files[$i]['name'].'</td>';
$fileoutput.=' <td width="100">'.$files[$i]['size'].'</td>';
$fileoutput.='</font></td></tr>';
$fileoutput.='</table><p>';
}
}
And here is the code that determines what $files[$i]['name'] is:
if ($dh = opendir($dir)) {
$dircount=0;
$filecount=0;
while (($file = readdir($dh)) !== false) {
if(filetype($dir.$file)=="dir"){
$dircount++;
if($dircount > 2){
$dir_names[$dircount-2] = $file;
}
} else {
$filecount++;
$files[$filecount]['name'] = $file;
}
The problem is, the image script isn't determining the dimentions for each individual image, and i'm not sure how to fix this..