write file to upload folder

Hello, everyone,
I’m creating a scheduled process that creates a note for a certain quote with an attached file.
The file attached to the note is read by a REST API. I thought to use a simple fwrite() in php:


 $fp = fopen('/upload/'.$noteBean->id, 'w');
 fwrite($fp, $result);
 fclose($fp);

The problem is that I can’t write the file, it seems that there are no write permissions.

Warning: fopen(/upload/34d2fe44-7ee0-d244-5415-5d4aa1d69d29): failed to open stream: No such file or directory in /var/www/sites/x-crm-dev/custom/TheImportOfferte.php on line 57

Are there other methods to write a file in suitecrm?

Hello
Try this :

$fp = fopen('upload/'.$noteBean->id, 'w');

Or check the code at modules/Notes/controller.php

1 Like

you could also try:

  $fp = fopen($_SERVER['DOCUMENT_ROOT'] . 'upload/'.$noteBean->id, 'w');   

also you may find this useful. https://pgorod.github.io/How-Documents-Stored/

1 Like

That’s perfect,
using $fp = fopen(‘upload/’.$noteBean->id, ‘w’);
it works.
Thanks :slight_smile:

Cheers!!