-1

I can let a user upload a file and save it in a folder but when I try to rename it with:

$date = date('d/m/o!G:i');
rename("/var/www/html/Images/CommonImages/{basename($_FILES['postfile']['name'])}","/var/www/html/Images/CommonImages/{$_SESSION['username']}/{$date}.{$imageFileType}");

It gives me this this Parse error:

syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

Probably it's something stupid...

superuser
  • 57
  • 1
  • 7
  • Possible duplicate of [PHP Parse/Syntax Errors; and How to solve them?](http://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – HPierce Sep 18 '16 at 19:57

1 Answers1

2

Don't try to execute functions inside a string... Use concatenation:

Change:

"/var/www/html/Images/CommonImages/{basename($_FILES['postfile']['name'])}"

To:

"/var/www/html/Images/CommonImages/" . basename($_FILES['postfile']['name'])

You should really get used to using concatenation instead of putting variables inside strings. Even though PHP allows variables inside strings, most other languages do not. In my opinion, code is much cleaner with concatenation because you can easily see which parts are static strings and which parts are variables:

"/var/www/html/Images/CommonImages/" . $_SESSION['username'] . "/" . $date . "." . $imageFileType
Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95