Giulio Giulio - 4 months ago 16
PHP Question

Unknown Parse error when trying to rename an uploaded file

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');

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...


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




"/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