Hi all,

In a secured php document I have a file uploader that was only for PDFs but they want xlsx, xls, ,docx, txt, rtf and ppt file extensions.

To filter the files coming in I have this:

$allowedExtensions = array("txt","csv","htm","html","xml", 
    "css","doc","xls","rtf","ppt","pdf","xlsx","docx"); 
  foreach ($_FILES as $file) { 
    if ($file['tmp_name'] > '') { 
      if (!in_array(end(explode(".", 
            strtolower($file['name']))), 
            $allowedExtensions)) { 
       die($file['name'].' is an invalid file type!'); 
      } 
    } 
  }

Once the check is done i am ready for upload. The only thing is how do I get the name of the file that is being uploaded and store it as the filename to be displayed for download purposes. This is what I have now:

$result = move_uploaded_file($_FILES['files']['tmp_name'], 
          FILEREPOSITORY."/$file");

          if ($result == 1) echo "<p>File successfully uploaded.</p>";
               else echo "<p>There was a problem uploading the file.</p>";

Thanks for any help on this in advance.

Recommended Answers

All 3 Replies

use $_FILES to get the original file name and store in the database or any place you like.

Both great solutions and exactly what I was looking for. Thanks greatly for the help!!!

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.