How to get Document content through PHP code

bsoremsugar —  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();
$doc->retrieve('1f915a68-53d8-c2dc-ee91-51828250d1d4');
$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

  1. 

    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.

        ‘array_diff_uassoc’,
        ‘array_diff_ukey’,
        ‘array_filter’,
        ‘array_intersect_uassoc’,
        ‘array_intersect_ukey’,
        ‘array_map’,
        ‘array_reduce’,
        ‘array_udiff_assoc’,
        ‘array_udiff_uassoc’,
        ‘array_udiff’,
        ‘array_uintersect_assoc’,
        ‘array_uintersect_uassoc’,
        ‘array_uintersect’,
        ‘array_walk_recursive’,
        ‘array_walk’,
        ‘uasort’,
        ‘uksort’,
        ‘usort’,

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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