Simple PHP file upload form

Ganz simples Upload script in PHP ohne grosse überprüfungen oder sonstiges...

  1. <?php
  2. // setze time limit auf unendlich
  3. if($_POST["submit"] == "upload"){
  4.         // Das Formular wurde gesendet
  5.         if($_FILES['file']['error'] != ) {
  6.                 echo "tmp_name = ".$_FILES["file"]["tmp_name"]."<BR>";
  7.                 echo "error code: ".$_FILES['file']['error']."<br>";
  8.                 die(" The file hasn't arrived the server");
  9.         }
  10.         // kopiere das temporäre file an den richtigen ort
  11.         if(copy($_FILES["file"]["tmp_name"], $_FILES["file"]["name"])) {
  12.                 echo "File upload succesful!<br>";
  13.                 echo "Name: " . $_FILES["file"]["name"] . "<br>";
  14.                 echo "Size: " . $_FILES["file"]["size"] . " Byte<br>";
  15.                 echo "MIME-Type: " . $_FILES["file"]["type"] . "<br>";
  16.                 echo "Link: <a href=\"" . $_FILES["file"]["name"] . "\">" . $_FILES["file"]["name"] . "</a><br><br>";
  17.         }
  18.         else {
  19.                 echo "File upload failed.";
  20.         }
  21. }
  22. // Das Formular wird angezeigt
  23. ?>
  24. <form enctype="multipart/form-data" action="<?php echo $PHP_SELF; ?>" method="post">
  25.         <input name="file" type="file">
  26.         <input type="submit" name="submit" value="upload">
  27. </form>

Trackback URL for this post:

http://www.2030.tk/trackback/152

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Use <fn>...</fn> to insert automatically numbered footnotes.
  • You can use the <go> tags just like the <a> for nicer urls.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.