0

hi i have a following form in html:

<form action="upload_file.php" method="post" enctype="multipart/form-data"> File Name: <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form>

and here is my upload_file.php

if (($_FILES["file"]["type"] != "file/XML"))

  {
  echo "Invalid file type";
  }
  else
  {
    echo 'file is uploaded';
  }

it give Invalid file type i want to upload a file of .xml
help me in this regard

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by Robert1995
1

Go ahead and try this :

    /**
     * @static
     * @param $filename
     * @param bool $comma
     * @return bool|string
     */
    public static function getFileExtension($filename, $comma = false) {
      if (strrpos($filename, '.')){
        $extension = substr($filename, strrpos($filename, '.'));

        return $comma ? $extension : substr($extension, 1);
      } else
         return false;

   }

Also, make sure you use this only on upload

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.