Besten Dank an Alle! error_reporting hat gefunzt wie nix.
Hab nochmals etliches gefixed und das ganze vollendet. Sozusagen als dankeschön an die Menschheit
Hier ist das fertige LAUFFÄHIGE skript
PHP-Code:
<?
error_reporting(E_ALL); //showing all php problems
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
//- TURN ON THIS DEBUG INFO, IF YOU NEED HELP
//echo 'Here is some debugging info:';
//print_r($_FILES);
//echo '
';
/* SUBMITTED INFORMATION - use what you need
* errorcode : $errorcode
* original filename : $imgfile_name
* temporary filename : $imgfile_temp
* size of uploaded file : $imgfile_size
* mime-type of uploaded file : $imgfile_mimetype
*/
$errorcode = ($_FILES['imgfile']['error']); // 0 is good
$imgfile_temp = ($_FILES['imgfile']['tmp_name']);
$imgfile_name = ($_FILES['imgfile']['name']);
$imgfile_size = ($_FILES['imgfile']['size']);
$imgfile_mimetype = ($_FILES['imgfile']['type]);
/*== upload directory where the file will be stored
relative to where script is run ==*/
$uploaddir = ".\\"; // this is the currentdir .\ for windows, please change to your os (preffered linux)
if ($errorcode!=0)
{
//there was probalby no file given
$error1="<h1>ERROR</h1>Please specify a file for uploading
";
}
else //errocode = 0
{
/* get file extension ==*/
$fileExtension = strrchr($imgfile_name,".");
/*== check fileextesion, if not correct do not allow upload ==*/
// echo "name: ".$imgfile_name."filextension: ".$fileExtension;
$fileExtension = strtolower($fileExtension);
if (($fileExtension != ".jpg") && ($fileExtension != ".jpeg"))
{
$error1 = "<h1>ERROR</h1>Image Extension Unknown.
";
$error2 = "Please upload only a JPEG image with the extension .jpg or .jpeg ONLY
";
$error3 = "The file you uploaded had the following extension: $fileExtension</p>\n";
/*== delete uploaded file ==*/
//unlink($imgfile_name);
}
else
{
//-- CHECK FILE SIZE OF UPLOADED IMAGE
$maxfilesize = 100000; //in bytes , 1024 = 1 Kbyte
if ($imgfile_size > $maxfilesize)
{
$error1 = "
<h2>ERROR</h2>Imagesfilesize is bigger as ".$maxfilesize;
$error2 = "
Your file has the size ".$imgfile_size."
";
}
else
{
//-- CHECK IMAGE SIZE OF UPLOADED IMAGE
$imgsize = GetImageSize($imgfile_temp);
/*== check size 0=width, 1=height ==*/
$maxwidth = 2500;
$maxheight = 2500;
if (($imgsize[0] > $maxwidth) || ($imgsize[1] > $maxheight))
{
$error1 = "
<h2>ERROR</h2>Imageszize is bigger as ".$maxwidth."x".$maxheight;
$error2 = "
Your image has width ".$imgsize[0]." and height ".$imgsize[1]."
";
}
else
{
/*== setup final file location and name ==*/
/*== change spaces to underscores in filename ==*/
$final_filename = str_replace(" ", "_", $imgfile_name);
$newfile = $uploaddir.$final_filename;
/*== do extra security check to prevent malicious abuse==*/
if (is_uploaded_file($imgfile_temp))
{
/*== the file exists only temporary therefore we copy file to proper directory ==*/
//if (!copy($imgfile,$newfile))
if (!move_uploaded_file($imgfile_temp,$newfile))
{
/*== if an error occurs the file could not be written, read or possibly does not exist ==*/
print "Error Uploading File.";
}
else
{
//- DEBUG INFO
//echo"File is succesfully copied to ".$newfile;
$newimage = "<img src=\"".$final_filename."\">";
/*== DO WHATEVER ELSE YOU WANT
SUCH AS INSERT DATA INTO A DATABASE ==*/
}
}
}
}
}
}
}
else
{
$debug = "POST conditions are not true";
}
?>
<html>
<head>
<title>Image upload test</title>
</head>
<body bgcolor="#FFFFFF">
<? if (isset($error1)) echo $error1 ?>
<? if (isset($error2)) echo $error2 ?>
<? if (isset($error3)) echo $error3 ?>
<? if (isset($newimage)) echo $newimage."
" ?>
<h2>Upload an Image</H2>
<form action="upload-test.php" method="POST" enctype="multipart/form-data">
Upload Image: <input type="file" name="imgfile">
<font size="1">Click browse to upload a local file</font>
<input type="submit" value="Upload Image">
</form>
</body>
</html>