AnsweredAssumed Answered

create txt file and attach documents custom code

Question asked by Francisco Javier Garcia on Oct 21, 2019
Latest reply on Mar 6, 2020 by Michael Gallant


I am trying to create a csv or txt file that contains comma separated records, I still don't understand how to do it if the fopen functions for the cloud environment are blacklisted.
Anyone have any idea how I could do this?

Add these include/utils/file_utils.php and  include/utils/sugar_file_utils.php 

And check the following link…  


This is my code, if you generate the file and save it in upload but do not attach it to the document to download.

 public function buildFileCsv()
        $GLOBALS['log']->fatal(" Construyendo archivos ");

        $filename = "PruebaTactos1.txt";
        //$cachefile = sugar_cached('upload/').$filename;
        $fp = sugar_fopen($directorio, 'w');
        fwrite($fp, "\n Agregamos otra linea mas");
       // return($cachefile);
         $GLOBALS['log']->fatal(" CAche file ->  ".$fp);
         $nombre = $filename;
        $document = BeanFactory::newBean('Documents');
        $document->name = $nombre;
        $document->active_date = date("Y-m-d");



        $docRevision = new DocumentRevision();
        $docRevision->revision = 1;
        $docRevision->document_id = $document->id;
        $docRevision->filename = $document->name;
        //$docRevision->file_ext = 'txt';
        //$docRevision->file_mime_type = 'text/plain';
        //$docRevision->assigned_user_id = $this->idUsr;

        $GLOBALS['log']->fatal("Documento " . $document->id . "  Revision  " . $docRevision->id . "  usuario  " . $this->idperiodo);
         //$uploadFile = new UploadFile();
         //get the file location
       // $uploadFile->temp_file_location = UploadFile::get_upload_path($docRevision->id);
       // $file_contents = $uploadFile->get_file_contents();
// $GLOBALS['log']->fatal(" Upload file content->  ".$file_contents);
      // $this->Output('upload/' . $docRevision->id, 'F');

Could you support me.


Thank you.