Unable to access (billede upload)
Når jeg forsøger at uplaode får jeg følgende fejl...Warning: imagejpeg() [function.imagejpeg]: Unable to access './customers/stutterisunhill.dk/stutterisunhill.dk/httpd.www.'/images/olympiahill.jpg in /customers/stutterisunhill.dk/stutterisunhill.dk/httpd.www/new/pages/add.php on line 44
Warning: imagejpeg() [function.imagejpeg]: Invalid filename in /customers/stutterisunhill.dk/stutterisunhill.dk/httpd.www/new/pages/add.php on line 44
Det fejlede at resize billedet : './customers/stutterisunhill.dk/stutterisunhill.dk/httpd.www.'/images/olympiahill.jpg! Prøv igen
__________________________________
Scriptet:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
mysql_connect("", "", "") or die(mysql_error());
mysql_select_db("");
if (isset($_POST['submit'])) {
$txt = $_POST['txt'];
$img = $_FILES['userFile']['name'];
// Her indsætte data i databasen.
$sql = "INSERT INTO billeder SET
txt = '$txt',
img = '$img'";
if (@mysql_query($sql)) {
echo '<p>Tilføjet indlæg</p>';
} else {
echo '<p>Error: ' . mysql_error() . '</p>' ;
}
}
// Function til at resize billede
function resize( $filename, $newfilename, $maxw, $maxh )
{
$srcim = imagecreatefromjpeg( $filename );
$ow = imagesx( $srcim );
$oh = imagesy( $srcim );
$wscale = $maxw / $ow;
$hscale = $maxh / $oh;
$scale = ( $hscale < $wscale ? $hscale : $wscale );
$nw = round( $ow * $scale, 0 );
$nh = round( $oh * $scale, 0 );
$dstim = imagecreatetruecolor( $nw, $nh );
imagecopyresampled( $dstim, $srcim, 0, 0, 0, 0, $nw, $nh, $ow, $oh );
imagejpeg( $dstim, $newfilename, 85 ); // 85 er kvaliteten på billede 100 er max.
imagedestroy( $dstim );
imagedestroy( $srcim );
return file_exists($newfilename);
}
// Function slut
// Variabler, her skal du rette $uploadDir, $maxHeight, $maxWidth.
// Functionen holder aspect så derfor skal $maxHeight og $maxWidth være ens.
$uploadDir = "'.$_SERVER[DOCUMENT_ROOT].'/images/"; //Husk mappen skal chmod'es til 644, hvor skal billede ligge
$maxHeight = 500; // Indstil max højde
$maxWidth = 500; // Indstil max bredde
$maxSize = 4; //Angives i MB
$pics = array('jpeg','jpg','jpe'); //Hvilke filtyper vil vi godtage? Kun .jpg
$maxSize = $maxSize * 1024 * 1024;
if($_FILES['userFile']['size'] > 0)
{
$uploadfile = $uploadDir . basename($_FILES['userFile']['name']);
if($_FILES['userFile']['size'] > $maxSize)
{
echo "Dit billede er for stort, prøv med mindre...";
exit();
}
$ext = strtolower(end(explode('.',$_FILES['userFile']['name'])));
if(!in_array($ext,$pics))
{
echo "Forkert billede format, prøv med et andet...";
exit();
}
if(!resize( $_FILES['userFile']['tmp_name'], $uploadfile, $maxWidth, $maxHeight ))
{
echo "Det fejlede at resize billedet : " . $uploadfile . "! Prøv igen<br />";
}
else
{
echo '<p>Billede er nu Tilføjet</p>';
}
}
?>
<FORM enctype="multipart/form-data" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<label>Tekstfelt:</label>
<textarea name="txt"></textarea>
<label>Billede:</label>
<input name="userFile" type="file"/>
<input type="submit" name="Submit" value="Send"/>
</FORM>
</body>
</html>
