file upload php Script für Bilder

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • file upload php Script für Bilder

    wenn die datei größer als MAX_FILE_SIZE ist, soll das script einen Fehler melden.

    Quellcode

    1. <?php
    2. switch($s) {
    3. default:
    4. ?>
    5. <form enctype="multipart/form-data" action="test.php?s=2" method="post">
    6. <input type="hidden" name="MAX_FILE_SIZE" value="30000">
    7. Send this file: <input name="userfile" type="file">
    8. <input type="submit" value="Send File">
    9. </form>
    10. <?php
    11. break;
    12. case 2:
    13. $uploaddir = '/aaa/images/';
    14. print "<pre>";
    15. if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])) {
    16. echo "Datei erfolgreich hochgeladen";
    17. } else {
    18. echo "Fehler!";
    19. }
    20. break;
    21. }
    22. ?>
    Alles anzeigen
  • hab hier was nützliches gefunden
    [phpdoc]is_uploaded_file[/phpdoc]

    Quellcode

    1. if (is_uploaded_file($userfile)) {
    2. //include code to copy tmp file to final location here...
    3. }else{
    4. switch($HTTP_POST_FILES['userfile']['error']){
    5. case 0: //no error; possible file attack!
    6. echo "There was a problem with your upload.";
    7. break;
    8. case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
    9. echo "The file you are trying to upload is too big.";
    10. break;
    11. case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
    12. echo "The file you are trying to upload is too big.";
    13. break;
    14. case 3: //uploaded file was only partially uploaded
    15. echo "The file you are trying upload was only partially uploaded.";
    16. break;
    17. case 4: //no file was uploaded
    18. echo "You must select an image for upload.";
    19. break;
    20. default: //a default error, just in case! :)
    21. echo "There was a problem with your upload.";
    22. break;
    23. }
    Alles anzeigen