Jump to content

Can someone explain this file upload script?


TeddyKiller

Recommended Posts

This is basic stuff, however I'm new to file uploads.

Can someone explain it out?

 

            if ((($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) {
                if ($_FILES["file"]["error"] > 0) {
                    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
                } else {
                    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
                    echo "Type: " . $_FILES["file"]["type"] . "<br />";
                    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
                       echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

                       if (file_exists("upload/" . $_FILES["file"]["name"])) {
                        echo $_FILES["file"]["name"] . " already exists. ";
                    } else {
                        move_uploaded_file($_FILES["file"]["tmp_name"],
                          "upload/" . $_FILES["file"]["name"]);
                         echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
                      }
                   }
             } else {
                echo "Invalid file";
            }

The script:

 

checks to see if it is a jpg image AND is less than 20K in size;

 

if an error is generated display the error.

 

If no error display the various file information.

 

check to see if same file name aready exists - if so display message; if not, finish uploading the file and display the info

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.