function header fejl
Hej exp...Jeg har en funktion til at lave thumbnail billeder:
<?php
function thumb($img,$mode= '0'){
if (!isset($w))
{
$w = 100;
}
if (!isset($h))
{
$h = 100;
}
SetType($mode, 'integer');
SetType($w, 'integer');
SetType($h, 'integer');
SetType($img, 'string' );
function percent($p, $w)
{
return (real)(100 * ($p / $w));
}
function unpercent($percent, $whole)
{
return (real)(($percent * $whole) / 100);
}
// Initialization
// Make sure the file exists...
if (!file_exists($img))
{
echo "Error: could not find file: $img.";
exit();
}
// If the user defined a type to use.
if (!isset($type))
{
$ext = explode('.', $img);
$ext = $ext[count($ext)-1];
switch(strtolower($ext))
{
case 'jpeg' :
$type = 'jpg';
break;
default :
$type = $ext;
break;
}
}
// Create the image...
switch (strtolower($type))
{
case 'jpg':
$tmp = imagecreatefromjpeg($img);
break;
case 'gif':
$tmp = @imagecreatefromgif($img);
break;
case 'png':
$tmp = @imagecreatefrompng($img);
break;
default:
echo 'Error: Unrecognized image format.';
exit();
break;
}
if ($tmp)
{
// Resize it
$ow = imagesx ($tmp); // Original image width
$oh = imagesy ($tmp); // Original image height
if ($mode)
{
// Just smash it up to fit the dimensions
$nw = $w;
$nh = $h;
}
else
{
// Make it proportional.
if ($ow > $oh)
{
$nw = $w;
$nh = unpercent(percent($nw, $ow), $oh);
}
else if ($oh > $ow)
{
$nh = $h;
$nw = unpercent(percent($nh, $oh), $ow);
}
else
{
$nh = $h;
$oh = $w;
}
}
$out = imagecreate($nw, $nh);
imagecopyresized($out, $tmp, 0, 0, 0, 0, $nw, $nh, $ow, $oh);
imagedestroy($tmp);
}
else
{
echo 'Could not create image resource.';
exit;
}
if ($out)
{
switch (strtolower($type))
{
case 'jpg':
header('Content-type: image/jpeg');
imagejpeg($out);
break;
case 'gif':
header('Content-type: image/gif');
imagegif($out);
break;
case 'png':
header('Content-type: image/png');
imagepng($out);
break;
}
imagedestroy($out);
}
else
{
echo 'ERROR: Could not create resized image.';
}
}
thumb("images/3.jpg");
?>
Hvis jeg kalder den sådan her uden nogen som helst form for html kode virker den fint. Men hvis jeg fx.
<?
echo "Billede nr: 1";
thumb("images/3.jpg");
?>
Så for jeg denne her fejl...
billede nr: 1
Warning: Cannot add header information - headers already sent by
Hvad kan jeg gøre for at undgå dette???
