Upload billede fil
Har problemer med at ligge billeder (ved godt at koden kun tillader jpg). Selvom jeg vælger en billedefil så er form værdien tom når jeg prøver at se dens value.Nogen som kan hjælpe?
<?
$konfiguration["upload_bibliotek"] = "./vareimg";
$konfiguration["max_stoerrelse"] = "250";
list($major, $minor, $rev) = explode(".", phpversion());
if($major < 4) {
die("Jeg kan kun arbejde med PHP 4.0.0 eller derover");
}
if($minor < 1) {
$_FILES = $HTTP_POST_FILES;
$_POST = $HTTP_POST_VARS;
$_SERVER = $HTTP_SERVER_VARS;
}
if( ($_POST[vare] != "") ){
if($_FILES["upfil"]["size"] > 0) {
$nytfilnavn = time();
$fra = $_FILES["upfil"]["tmp_name"];
$til = $_FILES["upfil"]["name"];
$split = explode('.', $til);
$til = $nytfilnavn.".".$split[1];
$tilthumbs = $nytfilnavn.".".$split[1];
$a=getimagesize($fra);
$width=$a[0]; $height=$a[1];
}
echo "<h2>- ".$_FILES["upfil"]["tmp_name"]." -</h2>";
echo "<h2>- ".$til." -</h2>";
if($_FILES["upfil"]["size"] > 0) {
$til = $konfiguration["upload_bibliotek"]."/".$nytfilnavn.".".$split[1];
$fil_stoerrelse = filesize($fra)/1024;
if($fil_stoerrelse > $konfiguration["max_stoerrelse"]) {
die("Desværre - filen er for stor. Jeg accepterer kun " .
$konfiguration["max_stoerrelse"] . "kb, og din fil fylder " .
ceil($fil_stoerrelse) . "kb");
}
if(function_exists("move_uploaded_file")) {
move_uploaded_file($fra, $til);
} else {
copy($fra, $til);
}
#### FULL ####
$picfile = $til;
$dir = $konfiguration["upload_bibliotek"]."/";
$picfileonly = $tilthumbs;
$image->properties = getimagesize($picfile);
if ($image->properties[2] == 2)
{
// create image based on file
// index 0 contains width
// index 1 contains height
$image->org_image = imagecreatefromjpeg($picfile);
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($picfile);
if(160 < $height_orig)
{
$height = 160;
$width = ($height / $height_orig) * $width_orig;
# $height = ($width / $width_orig) * $height_orig;
}
else {
$width = $width_orig;
$height = $height_orig;
}
// create new truecolour image - define thumb size here!
$image->new_image_thumb = imagecreatetruecolor($width, $height);
// resample original image
imagecopyresampled($image->new_image_thumb, $image->org_image, 0, 0, 0, 0, $width, $height, $image->properties[0], $image->properties[1]);
// create file (needed for safe mode)
touch($dir . "" . $picfileonly);
// save thumb file
imagejpeg($image->new_image_thumb, $dir . $picfileonly, 100);
}
#### MINI ####
$picfile = $til;
$dir = $konfiguration["upload_bibliotek"]."/";
$picfileonly = $tilthumbs;
$image->properties = getimagesize($picfile);
if ($image->properties[2] == 2)
{
// create image based on file
// index 0 contains width
// index 1 contains height
$image->org_image = imagecreatefromjpeg($picfile);
$width = 103;
$ratio = 100 / $image->properties[0];
$height = $ratio * $image->properties[1];
// create new truecolour image - define thumb size here!
$image->new_image_thumb = imagecreatetruecolor($width, $height);
// resample original image
imagecopyresampled($image->new_image_thumb, $image->org_image, 0, 0, 0, 0, $width, $height, $image->properties[0], $image->properties[1]);
// create file (needed for safe mode)
touch($dir . "thumb_" . $picfileonly);
// save thumb file
imagejpeg($image->new_image_thumb, $dir . "thumb_" . $picfileonly, 100);
}
}
echo "Så er varen tilføjet!";
}
?>
<form method="post" enctype="multipart/form-data">
Billede: (<a href="#" title="Der må ikke være danske tegn i filnavnet!!">NB!</a>)<br>
<input type="file" name="upfil"><br>
<input type="submit" value=" Tilføj " class="input">
</form>