How to get Document content through PHP code

sugarcrmdevelopers —  May 15, 2013 — 3 Comments

We’ve covered grabbing Documents over Web Services in the past, but how about if you are wanting to do it inside the Sugar code base itself? Try this snippet for a guide…

$doc = new Document();
$download_location = "upload://{$doc->document_revision_id}";
$file_contents = file_get_contents($download_location);

Thanks to Mindblocker on this forums post for the answer.

3 responses to How to get Document content through PHP code


    A useful snippet, but file_get_contents is a blacklisted function. If you were to create a Module-Installable package with that, it would be rejected by every OnDemand system and any on premise systems that enable security scanning of packages.

    On premise installations could get around this by adding file_get_contents to $GLOBALS[‘sugar_config’][‘moduleInstaller’][‘blackListExempt’] but my understanding is that OnDemand systems do not allow this.


      Hello @twitter-121527680:disqus

      The sugar function sugar_file_get_contents is-it too blacklisted for OnDemand?

      Also perhaps you can try this:

      require_once 'include/upload_file.php';
      $uf = new UploadFile();
      $uf->temp_file_location = $download_location;
      $file_contents = $uf->get_file_contents();


        It is indeed. You can always find the most recent list in the core file ModuleInstall/ModuleScanner.php, the ModuleScanner::blackList array. There’s also a set of blacklisted classes there.

        I’ve just found out that as of 6.7.0 (maybe 6.6.x) there’s several additions to the list, including anything with a callback function. That includes lots of array-manipulation methods.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s