I am trying to get the file to upload an image or audio file to the following directory
$dir='sites/default/documents/"$patientID"/'
but I don't know how to use the exact syntax with the $
sign inside a path.
I used the get method to get the patientID from the controller but still nothing is working
Use this instead : $dir="sites/default/documents/$patientID/";
In your case the variable is considered as a text.
Single quotes do not interpolate values, even if there are double quotes inside them. The initial string must be a double quote string, in order for any interpolation to occur inside of it.
If there's any doubt about the complexity of the variable name, use braces to encapsulate the interpolation. $dir="sites/default/documents/{$patientID}/";