Applies to PHPRunner 6.x-8.x. Paste this code to BeforeAdd/BeforeEdit events and replace UploadFieldName with the actual field name.

Note that this code only makes sense in 'Basic upload control' mode. In standard mode timestamp is added to file name automatically.


// field name that stores uploaded file name
$field
="UploadFieldName";
global $pageObject;
foreach( $pageObject->filesToMove as $key=>$val)
{
 
if($pageObject->filesToMove[$key]->sourceFilename==$_FILES["value_".$field."_".postvalue("id")]["tmp_name"]) {

        $fileName
= $values[$field];
        $ext
= ".".pathinfo($fileName, PATHINFO_EXTENSION);
        $name
= basename($fileName, $ext);
        $newFileName
= $name."_".date('YmdHis').$ext;
        $values
[$field]=$newFileName;
        $pageObject
->filesToMove[$key]->destFilename = $newFileName;
       
}
}
return true;

Post a Comment