Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#825879
Hello,
I am using a MultipleFile field to upload some files (different formats), I would to update the name of uploaded files. For that I used a trigger that fire after Dynaform where I am using the AppDocument::update()
Code: Select all
          //Code
            //...                  
            $d = new AppDocument();
            $aFileInfo = $d->Load($doc['APP_DOC_UID'], $doc['DOC_VERSION']);
            $aFileInfo['APP_DOC_FILENAME'] = $filename;
            $d->update($aFileInfo);
            //...                  
In the database, the field 'APP_DOC_FILENAME' (in table “APP_DOCUMENT”) contains the new value of file title. However, these new values don’t show up in the files list in form and all files keep their original titles.
I did another test of the update function on File Field and it is working properly.

Can you please assist me on this?
Regards
#825881
With MultipleFile field files, you need to also change the file's "name" in the MultipleFile's variable.

For example, to change the filename of the first file uploaded to a MultipleFile field whose variable is "myMultiFile":
Code: Select all
if (count(@=myMultiFile) >= 1) {
     $newFilename = 'myFilename.txt';
     @=myMultiFile[0]['name'] = $newFilename;

     $d = new AppDocument();
     $aFileInfo = $d->Load(@=myMultiFile[0]['appDocUid'], @=myMultiFile[0]['version']);
     $aFileInfo['APP_DOC_FILENAME'] = $newFilename;
     $d->update($aFileInfo);
}
#825886
You need to duplicate my code for each multipleFile variable. As my example shows, you need to both change the filename in the variable and the filename in the database.

If you want to change all the filenames of the files that were uploaded to a MultipleFile field, then use a for loop like this:
Code: Select all
for ($i=0; i < count(@=myMultiFile); i++) {
     $newFilename = 'myFilename.txt';
     @=myMultiFile[i]['name'] = $newFilename;

     $d = new AppDocument();
     $aFileInfo = $d->Load(@=myMultiFile[i]['appDocUid'], @=myMultiFile[i]['version']);
     $aFileInfo['APP_DOC_FILENAME'] = $newFilename;
     $d->update($aFileInfo);
}
#826080
Hello,
Thank you for your feedback.
I implemented your code but I did not get the desired result.
Once the trigger is executed, the file names are changing in the database but the modification does not occur in the variable. In addition, after the execution, the grid does not display the files list.
Here is the code to update the file name in DB:
Code: Select all
foreach($docs as $doc) {
	$ext= pathinfo($doc['APP_DOC_FILENAME'], PATHINFO_EXTENSION);
	$filename = 'myFilename.txt'. $ext;
	$d = new AppDocument();
	$aFileInfo = $d->Load($doc['APP_DOC_UID'], $doc['DOC_VERSION']);
	$aFileInfo['APP_DOC_FILENAME'] = $filename;
	$d->update($aFileInfo);         
}   
Here is the code to update the variable:

for ($i=0; i < count(@=myMultiFile); i++) {
     $newFilename = 'myFilename.txt';
     @=myMultiFile[i]['name'] = $newFilename;
     $d = new AppDocument();
     $aFileInfo = $d->Load(@=myMultiFile[i]['appDocUid'], @=myMultiFile[i]['version']);
     $aFileInfo['APP_DOC_FILENAME'] = $newFilename;
     $d->update($aFileInfo);
}
The content of myMultiFile before execution:
Code: Select all
Array 
( 
	[0] => Array ( [appDocUid] => 2645736005d5da472028a71039279911 [name] => PJ - 1.pdf [version] => 1 ) 
	[1] => Array ( [appDocUid] => 9728602535d5da472028a71085556719 [name] => PJ - 2.pdf [version] => 1 ) 
	[2] => Array ( [appDocUid] => 2024450075d5da472028a75000760256 [name] => PJ - 3.pdf [version] => 1 ) 
)
The content of myMultiFile after execution:
Code: Select all
Array ( 
	[0] => Array ( [appDocUid] => 2645736005d5da472028a71039279911 [name] => PJ - 1.pdf [version] => 1 ) 
	[1] => Array ( [appDocUid] => 9728602535d5da472028a71085556719 [name] => PJ - 2.pdf [version] => 1 ) 
	[2] => Array ( [appDocUid] => 2024450075d5da472028a75000760256 [name] => PJ - 3.pdf [version] => 1 ) 
	[i] => Array ( [name] => myFilename.txt ) 
)
Can you please assist me?
Regards
#826084
Oh, I made a mistake in my code. Change i to $i so it will be a variable.

Change your code to this:
Code: Select all
for ($i=0; $i < count(@=myMultiFile); $i++) {
     $newFilename = 'myFilename.txt';
     @=myMultiFile[$i]['name'] = $newFilename;
     $d = new AppDocument();
     $aFileInfo = $d->Load(@=myMultiFile[$i]['appDocUid'], @=myMultiFile[$i]['version']);
     $aFileInfo['APP_DOC_FILENAME'] = $newFilename;
     $d->update($aFileInfo);
} 
#826100
Hi,
I already made this modification and run the code, and then I got the results that I described earlier.
The codes to change the file name in DB and the variable are working without any error in PHP code. However, I did not get the desired result (modify also the file names in multipleFile field)
Please refer to previous post.
Best Regards.

A 1xbet clone script is a pre-designed software so[…]

4rabet clone script is enabling entrepreneurs to e[…]

Parimatch clone script is enabling entrepreneurs t[…]

In the world of cryptocurrency, a wallet is an app[…]