-2

I have a file upload script which works fine, however it currently saves the document under the original file name, I want to rename this on upload, ideally adding an ID number before it (from GET variable, below)

$employee=$_GET["id"];

The file upload script, where the name comes from is below:

$file_name = $key.$_FILES['files']['name'][$key];

How can I add the ID number before the name upon saving?

Shane
  • 753
  • 3
  • 8
  • 21
  • 1
    By concatenating your ID similar to how you're concatenating `$key` before it now – j08691 Oct 20 '16 at 22:19
  • Could you show me an example? As i'm not sure what you mean? – Shane Oct 20 '16 at 22:21
  • Well first off, what's `$key` in your code? In general you'd do something like `$file_name = $myID.$key.$_FILES['files']['name'][$key];` – j08691 Oct 20 '16 at 22:22

1 Answers1

1
$file_name = $employee . $key . $_FILES['files']['name'][$key];

Should suffice -- But it is considered very bad practice to act on any user-provided data without first sanitizing & validating it.

Check out: https://www.owasp.org/index.php/PHP_Security_Cheat_Sheet#Untrusted_data for more information.

You should first ensure that the $_GET['id'] variable fits the expected pattern, and is a valid employee ID -- at the very least!

Drefetr
  • 412
  • 2
  • 7