Search code examples
phpfileif-statementfile-rename

Rename file depending on select option


I have an upload system which uses the following code to define the file name:

$file_name = trim(basename(stripslashes($name)), ".\x00..\x20");

I have added a selectbox with a few options and what I want to do, is add add a word to the beginning of the filename, depending on which option is selected.

The if statement for the selectbox works fine however I'm a little stuck with adding the word "skin_" onto the beginning of the name. So far, I have this, but it doesn't seem to work:

if(isset($_POST['upload_type']) and $_POST['upload_type'] == 'skin') {
    $file_name = "skin_", trim(basename(stripslashes($name)), ".\x00..\x20");
}

Could someone please help?


Solution

  • You concat strings in PHP using . (a dot) instead of a ,:

    $file_name = "skin_" . trim(basename(stripslashes($name)) . ".\x00..\x20");