Error on uploading file with path and name

Hello,

I have a form and a files fields.
I would like scriptcase to rename the file and store in it a special path. I have configure the file’s field but I try to put that script on after insert in order to store it in a Table (so i can have a listing)

onafterinsert script

'// Récupération de MissionID et nom de fichier
$missionID = {ID};
$originalFileName = {file};
$reference = {Ref_assureur}

// Chemin vers le dossier upload
$uploadFolder = "/files/" . $reference . "/";

// Créer le dossier s'il n'existe pas
if (!is_dir($uploadFolder)) {
    mkdir($uploadFolder, 0777, true); // Création récursive du dossier avec permissions
}

// Nouveau nom de fichier avec MissionID comme préfixe
$newFileName = $reference . "_" . $originalFileName;

// Chemin complet du fichier
$filePath = "/files/" . $reference . "/" . $newFileName;

// Renommer et déplacer le fichier
rename("/files/" . $originalFileName, $filePath);

// Insérer dans la table mission_files
$sqlInsert = "
    INSERT INTO mission_files (MissionID, FileName, FilePath, UploadDate)
    VALUES ('$missionID', '$newFileName', '$filePath', NOW())
";
sc_exec_sql($sqlInsert);'

Meanwhile Scriptcase do not seems to consider $uploadfolder or $Newfilename and send a parse error: syntax error, unexpected variable

Does anyone have an idea for a workaround or a solution ?