0

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.

3
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by phaedrusGhost
0

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

0

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

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.