Ok, so I am creating an uploader for uploading files such as .udk or .upk as well as other basic files such as txt and html. But I have been tinkering with the code I found (i'm a noob) and I can't get it to accept those extra extensions.

Here is my code:

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "udk")
|| ($_FILES["file"]["type"] == "upk")
|| ($_FILES["file"]["type"] == "application/exe")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/bmp")
|| ($_FILES["file"]["type"] == "image/jpeg")
&& ($_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("dropbox/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. Please rename and try again.";
      }
    else
      {
      $yes = "<a href='/dropbox/" . $_FILES["file"]["name"] . "'>Confirm</a>";
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "dropbox/" . $_FILES["file"]["name"]);
      echo $yes;
      }
    }
  }
else
  {
  if (($_FILES["file"]["size"] < 20000)){
  echo "Your file is too big!";
  }
  else{
  echo "Invalid file";
  }
  }
?>

I was curious myself, so i wnt to the PHP site. not much info there about this!
However at the end there was a comment that might help:

If $_FILES is empty, even when uploading, try adding enctype="multipart/form-data" to the form tag and make sure you have file uploads turned on.

If not, I would put in a:

var_dump($_FILES["file"]["type"]);

to see what is actually being captured in the array.

I was curious myself, so i wnt to the PHP site. not much info there about this!
However at the end there was a comment that might help:


If not, I would put in a:

var_dump($_FILES["file"]["type"]);

to see what is actually being captured in the array.

Sweet. Worked perfectly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.