This articles has been requested to be deleted.
Wednesday, November 3rd 2010, 6:25pm
|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$imageinfo = @getimagesize($_FILES['datei']['tmp_name']); $allowed = array('image/gif', 'image/jpeg', 'image/png'); if(!$imageinfo || !isset($imageinfo['mime']) || !in_array($imageinfo['mime'], $allowed)) { throw new Exception('bildformat nicht erlaubt'); } $uploaddir = 'uploads/'; $uploadfile = $uploaddir . basename($_FILES['datei']['name']); if (move_uploaded_file($_FILES['datei']['tmp_name'], $uploadfile)) { echo "Upload erfolgreich."; } else { echo "Upload fehlgeschlagen."; } |
|
|
HTML Code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<!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" dir="ltr" xml:lang="de"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <title>PHP: Sicherer Bilder Upload</title> </head> <body> <?php if(isset($_FILES['datei'])) { $imageinfo = @getimagesize($_FILES['datei']['tmp_name']); $allowed = array('image/gif', 'image/jpeg', 'image/png'); if(!$imageinfo || !isset($imageinfo['mime']) || !in_array($imageinfo['mime'], $allowed)) { throw new Exception('bildformat nicht erlaubt'); } $uploaddir = 'uploads/'; $uploadfile = $uploaddir . basename($_FILES['datei']['name']); if (move_uploaded_file($_FILES['datei']['tmp_name'], $uploadfile)) { echo "Upload erfolgreich."; } else { echo "Upload fehlgeschlagen."; } } ?> <form action="" method="post" enctype="multipart/form-data"> <fieldset> <legend>Datei auswählen</legend> <input type="file" name="hiddendata" name="datei" /> <input type="submit" value="Upload starten" /> </fieldset </form> </body> </html> |