Skip to content

Instantly share code, notes, and snippets.

@glennpratt
Created October 11, 2011 21:22
Show Gist options
  • Select an option

  • Save glennpratt/1279488 to your computer and use it in GitHub Desktop.

Select an option

Save glennpratt/1279488 to your computer and use it in GitHub Desktop.
<?php
global $user;
// Create a file object.
$file = new stdClass();
$file->fid = NULL;
$file->uri = 'https://www.allplayers.local/g/low_level_group_2b/sites/default/files/imagecache/profile_normal/sites/all/modules/apci_features/apci_defaults/group-icon.png';
$url_parts = parse_url($file->uri);
$file->filename = basename($url_parts['path']);
$file->filemime = file_get_mimetype($file->uri);
$file->uid = $user->uid;
$file->status = FILE_STATUS_PERMANENT;
// file_save() calls filesize()... jerk!
$ret = file_save($file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment