Location: PHPKode > projects > NewsP > admin/upload.php
<?php include("auth.php");
$pfad = $_SERVER["SCRIPT_FILENAME"];
$pfad = str_replace("admin/upload.php", "", $pfad);

$jpg = ".jpg";
// Variabeln festlegen 
$max_byte_size = 10000000; 
$allowed_types = "(jpg|png)"; 

// Formular wurde abgeschickt 
if($_POST["submit"] == "Upload") { 

// Wurde wirklich eine Datei hochgeladen? 
if(is_uploaded_file($_FILES["file"]["tmp_name"])) { 

// Gültige Endung? ($ = Am Ende des Dateinamens) (/i = Groß- Kleinschreibung nicht berücksichtigen) 
if(preg_match("/\." . $allowed_types . "$/i", $_FILES["file"]["name"])) { 

// Datei auch nicht zu groß 
if($_FILES["file"]["size"] <= $max_byte_size) { 

// Alles OK -> Datei kopieren 

// Dateiendung ermitteln
$str_file_ext = substr( strtolower( strrchr($_FILES['file']['name'], '.') ), 1 );

####################
$datei = "gerd.$str_file_ext"; 
$size=getimagesize("$pfad/$datei"); 
$breite=$size[0]; 
$hoehe=$size[1]; 
if(copy($_FILES["file"]["tmp_name"], "$pfad/$datei")) { 
####################



$size=getimagesize("$pfad/$datei"); 
$breite=$size[0]; 
$hoehe=$size[1]; 
$new_w=468; 


if ($str_file_ext=="jpg"){
$dst_img=ImageCreateTrueColor($breite,$hoehe); 
$src_img=imagecreatefromjpeg("$pfad/$datei"); 
ImageCopyResized($dst_img,$src_img,0,0,0,0,$breite,$hoehe,ImageSX($src_img), ImageSY($src_img)); 
Imagejpeg($dst_img, "".$pfad."".$datei."");
}
if ($str_file_ext=="png"){
$dst_img=ImageCreateTrueColor($breite,$hoehe); 
imageAlphaBlending($dst_img, false);
imageSaveAlpha($dst_img, true);
$src_img=imagecreatefrompng("$pfad/$datei"); 
ImageCopyResized($dst_img,$src_img,0,0,0,0,$breite,$hoehe,ImageSX($src_img), ImageSY($src_img)); 
Imagepng($dst_img, "".$pfad."".$datei."");
}

$pic ="$pfad/$datei";

if($breite == "" ||  $hoehe == "")
	{
	$verz=opendir("bilder".$id."/"); 
	while ($file = readdir ($verz))  
		if($file != "." && $file != "..") 
			{ 
			unlink("bilder".$id."/".$file);	
			} 
	closedir($verz);
	}

echo "ja";

} else { 
echo "<CENTER><B>There has been a problem with uploading your file!</B><BR>Please choose your browser backbutton.<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;</CENTER>"; 
} 
} else { 
echo "<CENTER><B>To large file,the maximum filesize is " . $max_byte_size . " Byte.</B><BR>Please choose your browser backbutton.<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;</CENTER>"; 
} 
} else { 
echo "<CENTER><B>Illegal file type, only <FONT COLOR=\"#FF0000\">JPG</FONT> files are allowed.</B><BR>Please choose your browser backbutton.<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;</CENTER>"; 
} 
} else { 
echo "<CENTER><B>No file selected.</B><BR>Please choose your browser backbutton.<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;</CENTER>"; 
} 
} else { 
echo "Please use the upload form."; 
} 
?> 
Return current item: NewsP