0

I'm trying to move a file from one folder to another using the rename function, which I need to include a variable. I can't just use the working example below, as the code with first pull the variable file name from one of my databases (I have typed the variable in the second example for the purpose of this question).

WORKS FINE - no variable

<?php
rename('../downloads/test.docx', '../downloads/del/test.docx');
?>

DOESN'T WORK - with variable

<?php
$filetomove = 'test.docx';
rename('../downloads/.$filetomove.', '../downloads/del/.$filetomove.');
?>

Am I missing something obvious?

teddytash
  • 21
  • 4

1 Answers1

1

Do not use single quotes, use double quotes otherwise it will take it as literal and remove concatenation . from it.

rename("../downloads/$filetomove", "../downloads/del/$filetomove");

Strings

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Combinu
  • 882
  • 2
  • 10
  • 31