Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderators: ArturoRobles, ArturoRobles

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.
#790053
hi

I use PM version 3.1. The PHP example at
http://wiki.processmaker.com/3.1/REST_A ... doc_uid.7D

for downloading a generated output document, does not work. I can get the document information , but when downloading, It redirect me to the login page . It seems that downloading needs authentication while in the example nothing is done to authenticate when downloading the document.

thank you for helping me

regards
#790064
Hello surena,

By directly going to the link you won't be able to download, as you are not logged into ProcessMaker. The example reads the content of the file in the code and copies the data into another file on your local server which you will be able to access. The other way is to download the output document as an attachment in your browser, add the following code:
Code: Select all
if ($oRet->status == 200) {
   $link = 'http://' .$_SERVER['SERVER_NAME']. '/sysworkflow/en/neoclassic/' . $oRet->response->app_doc_link;
   //Download binary PDF file:
   $handle = fopen($link, "rb") or die("Error: Unable to open file:\n$link");
   $contents = stream_get_contents($handle) or die("Error: Unable to get file:\n$link");
   fclose($handle);  
   
   //serve up the PDF file for download as attachment in user's browser:
   header('Content-Description: File Transfer');
   header('Content-Type: application/octet-stream');
   header('Content-Disposition: attachment; filename="' . $oRet->response->app_doc_filename . '"');
   header('Content-Transfer-Encoding: binary');
   header('Expires: 0');
   header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
   header('Pragma: public');
   header('Content-Length: ' . strlen($contents));
   print $contents
   die;            //die here so that ?> at end of script isn't printed
}
Hope this helps.

Best Regards,
Zainab Sabunwala
Last edited by zainab on Wed Apr 05, 2017 3:09 am, edited 1 time in total.
#791832
I checked the sid=XXXXXXXXXXXX solution , but it did not work. I get the sessionid with login webservice and append it to the end of document url, but when downloading the document it gives me 302 result code and redirects me to login page
#791834
This one took me a while to figure this out. Here is what you need to do.
Edit the processmaker/workflow/engine/config/env.ini file with a plain text editor on your ProcessMaker server and add the following line:
Code: Select all
disable_download_documents_session_validation = 1
The URL to download an Output Document should be:
http://{PROCESSMAKER_DOMAIN}/sys{WORKSPACE}/{LANG}/{SKIN}/cases/cases_ShowOutputDocument?a={APP_DOC_UID&v={VERSION}&ext=pdf&PHPSESSID={PHP_SESSION_ID}

For example:
http://localhost:320/sysworkflow/en/neo ... 246mt4r7f2

If you want to prevent your web browser from using a cached copy of the document, then you can randomly generate a number using rand() and add random=XXXXXXX to the URL, like this:
http://localhost:320/sysworkflow/en/neo ... 246mt4r7f2

There are two ways to get the PHPSESSID, you can either login with web services as shown in http://wiki.processmaker.com/index.php/ ... atic_Login or you can add the following trigger to your process:
Code: Select all
$userId = @@USER_LOGGED;
$sql = "SELECT LOG_SID FROM LOGIN_LOG WHERE USR_UID='$userId' ORDER BY LOG_INIT_DATE DESC";
$result = executeQuery($sql);
@@sessionId = $result[1]['LOG_SID'];
In your script, call PUT /cases/{app_uid}/execute-trigger/{tri_uid} to execute the above trigger and then call GET /cases/{app_uid}/variables to get the value of the sessionId variable.
#793367
Hello Amos,

I am struggling with the similar kind of problem. I am basically generating an output document and sending the link of output document via email. When the receiver clicks on the link he is redirected to the login page. I tried your method and it still redirects me to the login page. Kindly help me here. Any idea why this could be happening?

Best Regards,
Zainab Sabunwala
#793398
Zainab,
If you are sending the link in an email, then the login session has already expired when it is clicked. It is better to not include the PHPSESSID=XXXXXXXX part if using it in a link in an email.
If you don't care about security than use this setting in your env.ini file:
Code: Select all
disable_download_documents_session_validation = 1  
Another option is to create a custom script and add a link in your email to execute that custom script which automatically logins with web services and then redirects to:
http://{PROCESSMAKER_DOMAIN}/sys{WORKSPACE}/{LANG}/{SKIN}/cases/cases_ShowOutputDocument?a={APP_DOC_UID&v={VERSION}&ext=pdf&PHPSESSID={PHP_SESSION_ID}

I have a suggest where user have to select some do[…]

The 500 Internal Server Error is the general catch[…]

Really very nice blog information for this one and[…]

This is a long, lengthy and cumbersome process. T[…]