Trouble uploading .xml file via PHP -


i'm trying create form user can upload xml file server overwrite 1 exists. i'm using code below (which know doesn't upload file if exists, i'll fix once i've fixed this).

the problem first if statement fails @ statement

($_files["file"]["type"] == "application/xml") 

meaning invalid file message. if comment out, file uploads.

changing file types allowed type (eg jpg) works.

<?php $allowedexts = array("xml"); $extension = end(explode(".", $_files["file"]["name"])); if ((($_files["file"]["type"] == "application/xml")) && ($_files["file"]["size"] < 5000000) && in_array($extension, $allowedexts))   {   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("xml/" . $_files["file"]["name"]))       {       echo $_files["file"]["name"] . " exists. ";       }     else       {       move_uploaded_file($_files["file"]["tmp_name"],       "xml/" . $_files["file"]["name"]);       echo "stored in: " . "xml/" . $_files["file"]["name"];       }     }   } else   {   echo "invalid file";   } ?> 

i'm new php gentle, have looked similar questions not found seems fix issue.

thanks.

from php website:

$_files['userfile']['type']

the mime type of file, if browser provided information. example "image/gif". mime type not checked on php side , therefore don't take value granted. 

"if browser provided information." browser don't send type. need validate via extension or parse xml.

check this.


Comments