Questions and discussion about using ProcessMaker: user interface, running cases & functionality
#812967
You can store an uploaded file in a BLOB field in MySQL, but it is better to save the path on the ProcessMaker server where the uploaded file is stored or the URL to access the file. This trigger example will show you how to save all this information. PM Tables don't offer BLOB fields, so you will need to create the table outside ProcessMaker in an external database.

Let's say that you have a table named "UPLOADED_FILES" in MySQL with the following fields:
CASE_ID: char(32)
CASE_NO: int(8)
PATH: varchar(255)
URL: varchar(255)
FILENAME: varchar(255)
CONTENTS: blob
UPLOADER: varchar(100)
UPLOAD_DATE: datetime
(with everything in the UTF-8 character set)

Create a Database Connection in ProcessMaker to the MySQL database and use its UID in the following trigger code which inserts the file contents and its path in the UPLOADED_FILES table:
Code: Select all
$db = '1234567890abcde1234567890abdce'; //set to UID of database connection
$caseId = @@APPLICATION;
$caseNo = @@APP_NUMBER;

//Get all the uploaded files for the current case.
//You can also search for a particular Input Document UID in DOC_UID or 
//a file uploaded to a particular File field in APP_DOC_FIELDNAME:
$sql = "SELECT * FROM APP_DOCUMENT WHERE APP_UID='$caseId' AND 
   APP_DOC_STATUS='ACTIVE' AND (APP_DOC_TYPE='ATTACHED' OR APP_DOC_TYPE='INPUT')";
$aFiles = executeQuery($sql, $db);

if (!is_array($aFiles)) {
   throw new Exception("Unable to execute query: $sql");
}

foreach ($aFiles as $aFile) {
   //lookup original filename:
   $oDoc = new AppDocument();
   $aFileInfo = $oDoc-> $oDoc->Load($aFile['APP_DOC_UID'], $aFile['DOC_VERSION']);
   $filename = mysql_real_escape_string($aFileInfo['APP_DOC_FILENAME']);
   
   $aUser = userInfo($aFile['USR_UID']);
   $uploader = $aUser['firstname'] .' '. $aUser['lastname'] .' ('. $aUser['username'] .')';
   $uploadDate = $aFile['APP_DOC_CREATE_DATE']; 
    
   $g = new G();
   $ext = pathinfo($filename, PATHINFO_EXTENSION);
   $path = mysql_real_escape_string(PATH_DOCUMENT . $g->getPathFromUID($caseId) . PATH_SEP .
      $aFile['APP_DOC_UID'] .'_'. $aFile['DOC_VERSION'] .'.'. $ext); 
   $contents = mysql_real_escape_string(file_get_contents($path));
     
   $url = "http://{$_SERVER['SERVER_ADDR]}:{$_SERVER['SERVER_PORT']}/sys" . @@SYS_SYS .
        "/en/neoclassic/cases/cases_ShowDocument?a={$aFile['APP_DOC_UID']}&v={$aFile['DOC_VERSION']}";

   $insert = "INSERT INTO UPLOADED_FILES 
     (CASE_ID, CASE_NO, PATH, URL, FILENAME, CONTENTS, UPLOADER, UPLOAD_DATE) 
     VALUES ('$caseId', $caseNo, '$path', '$url', '$filename', '$contents', '$uploader', '$uploadDate')";                    
   @@result = $executeQuery($sql, $db);
}
See:
http://wiki.processmaker.com/3.0/File_c ... se_storage
http://wiki.processmaker.com/3.0/Intern ... Load.28.29

I haven't tested this, so you might need to debug the code, but this is the basic idea.
#830298
Dear Amos

I've just done as you suggest for saving a file to a Table, although it does not work and the following error has been appread.

syntax error, unexpected 'SERVER_PORT' (T_STRING), expecting ']'

(1/1) ParseError
syntax error, unexpected 'SERVER_PORT' (T_STRING), expecting ']'

in class.pmScript.php(326) : eval()'d code line 33
at PMScript->executeAndCatchErrors()
in class.pmScript.php line 481
at PMScript->execute()
in Cases.php line 3372
at Cases->executeTriggerFromList()
in Cases.php line 3298
at Cases->executeTriggers()
in CasesTrait.php line 118
at Cases->routeCase()
in cases_Derivate.php line 98
at {closure}()
in cases_Derivate.php line 109
at require_once('C:\\pmlearning\\bpms\\workflow\\engine\\methods\\cases\\cases_Derivate.php')
in sysGeneric.php line 1076
at include('C:\\pmlearning\\bpms\\workflow\\public_html\\sysGeneric.php')
in app.php line 42


Please let me know, what is wrong, and how should I resolve this error?
OR
Please send tested code.

My main concern is about to retrieve the uploaded files of a case based on case number after a case is closed.
Error While Importing

Is it possible that the file that you are trying[…]

Version 5.4) inside workflow>public_html direct[…]

I'm new in processmaker and I need help in this si[…]

The forum content that you shared with me has prov[…]