Upload problem -
Hej;Jeg har et problem med min upload php-fil. Filen gemmer et bilelde i mappen 'upload' og viser det dernæst i en jpg-ramme. På localhost virker det fint... men når den kommer online får jeg fejlen:
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/getfile.php:10) in /var/www/html/getfile.php on line 118
Jeg har markeret linje 118 i teksten.
getfile.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da">
<head>
<title>FlushAd - Se din reklame her!</title>
<link rel="stylesheet" type="text/css" href="./style.css" />
</head>
<body>
<?php
$uploadDir = "/upload/";
$better_token = md5(uniqid(rand(), true));
$allowPics = array("jpg","jpeg","jpe");
$maxSize = 4096000;
$ramme = "./grafik/test2.jpg";
function LoadJpeg($imgname)
{
$im = @imagecreatefromjpeg($imgname); /* Attempt to open */
if(!$im)
{
/* See if it failed */
$im = imagecreate(150, 30); /* Create a blank image */
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
function LoadPNG($imgname)
{
$im = @imagecreatefrompng($imgname); /* Attempt to open */
if(!$im)
{
/* See if it failed */
$im = imagecreate(150, 30); /* Create a blank image */
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
function LoadGIF($imgname)
{
$im = @imagecreatefromgif($imgname); /* Attempt to open */
if(!$im)
{
/* See if it failed */
$im = imagecreate(150, 30); /* Create a blank image */
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
if($_FILES["userFile"]["size"] > 0)
{
$uploadfile = getcwd() . $uploadDir . $better_token;
if($_FILES["userFile"]["size"] > $maxSize)
{
echo "<p>Only pics below 4MB</p>";
exit();
}
$ext = strtolower(end(explode(".",$_FILES["userFile"]["name"])));
if(!in_array($ext,$allowPics))
{
echo "<p>Only pictures...</p>";
exit();
}
$uploadfile = $uploadfile . "." . $ext;
$src = LoadJpeg($_FILES["userFile"]["tmp_name"]);
$dst = LoadJpeg($ramme);
// Set a maximum height and width
$width = 52;
$height = 75;
// Get new dimensions
$width_orig = imagesx($src);
$height_orig = imagesy($src);
// Get RAMME dimensions
$width_ramme = imagesx($dst);
$height_ramme = imagesy($dst);
if ($width && ($width_orig < $height_orig))
{
$width = ($height / $height_orig) * $width_orig;
}
else
{
$height = ($width / $width_orig) * $height_orig;
}
// Resample
//$image_p = imagecreatetruecolor($width, $height);
//$image = imagecreatefromjpeg($filename);$width_ramme-(($width_ramme+$width)/2)$height_ramme-(($height_ramme+$height)/2)
imagecopyresampled($dst, $src, 600, 50, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($dst, $uploadfile, 100);
<b>linje 118</b> header("Location: " . $_SERVER['PHP_SELF'] . "?image=" . $better_token . "." . $ext);
exit();
}
if(isset($_GET['image']))
{
echo '<img src=".'.$uploadDir.$_GET['image'].'" alt="Uploaded Picture"/>';
}
?>
<div class="input">
<form enctype="multipart/form-data" action="<?=$_SERVER['PHP_SELF'];?>" method="POST">
<table>
<tr>
<td><input name="userFile" type="file" /></td>
<td colspan="2"><input type="submit" value="Send File" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
