File or Image Upload in PHP

This examples shows how to upload file or image in PHP

    <title>File Upload in PHP</title>
    <form method='post' action='<?php echo $_SERVER["REQUEST_URI"];?>' enctype='multipart/form-data'>
      <label>Select Image : </label>
      <input type='file' name='file' required>
      <input type='submit' name='submit' value='Upload'>
        $fileName=basename($_FILES["file"]["name"]); //Get File Name 
        $fileType=pathinfo($_FILES["file"]["name"],PATHINFO_EXTENSION);//Get File Extension
        $fileType=strtolower($fileType); //convert to lowercase
        $uploadFile=rand(1000,10000).rand(1000,10000).".".$fileType; //Set File name with Random Number
        //Check File Size greater than 300KB
          echo "Upload Failed.File Size is too Large!!!";
        //Check File Extension
        else if($fileType != 'jpg'&&$fileType != 'jpeg'&&$fileType != 'png' && $fileType != 'gif'){
          echo "Upload Failed.Invalid File!!!";
        //Check Upload Folder 
        else if(!is_dir($uploadFolder)){
          echo "Upload Failed.Upload Folder not exists!!!";
        //Check File Name
        else if(file_exists($uploadFile)){
          echo "Upload Failed.File Already Exists!!!";
        //Upload File
          //Move file into 'upload' Folder
            echo "Upload Success";
            echo "Upload Failed";