function uif_plus_upload_file in User Import Framework Plus 7
Handle file uploads for image and file fields
Parameters
array $account:
array $field_info:
string $value:
Return value
object $file
3 calls to uif_plus_upload_file()
- uif_plus_process_file_field in ./
uif_plus.module - Process import of file fields.
- uif_plus_process_image_field in ./
uif_plus.module - Process import of image fields.
- uif_plus_process_user_picture in ./
uif_plus.module - Process import of user pictures
File
- ./
uif_plus.module, line 506 - Advanced user import from a CSV file.
Code
function uif_plus_upload_file($account, $field_info, $value) {
// prepare file paths
$uif_plus_image_path = variable_get('uif_plus_image_path', '');
if (!strlen($uif_plus_image_path)) {
$uif_plus_image_path = file_default_scheme() . '://uif_plus';
}
$image_path = uif_plus_normalise_filepath($uif_plus_image_path) . DIRECTORY_SEPARATOR . uif_plus_normalise_filename($value);
// get file URI
if ($field_info['type'] == 'int') {
$picture_directory = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures');
file_prepare_directory($picture_directory, FILE_CREATE_DIRECTORY);
$pathinfo = pathinfo($image_path);
$uri = $picture_directory . '/picture-' . $account->uid . '-' . REQUEST_TIME . '.' . $pathinfo['extension'];
}
else {
$picture_directory = file_default_scheme() . '://';
file_prepare_directory($picture_directory, FILE_CREATE_DIRECTORY);
$pathinfo = pathinfo($image_path);
$uri = $picture_directory . '/' . $pathinfo['basename'];
}
// prepare for file upload
$info = image_get_info($image_path);
$destination = file_stream_wrapper_uri_normalize($uri);
// create file
$file = new stdClass();
$file->uid = 1;
$file->uri = $image_path;
$file->filemime = $info['mime_type'];
$file->status = 1;
$file->filesize = $info['file_size'];
$file->id = 1;
$file->display = 1;
// Move the temporary file into the final location.
if ($file = file_move($file, $destination, FILE_EXISTS_RENAME)) {
$file->status = FILE_STATUS_PERMANENT;
$file = file_save($file);
file_usage_add($file, $field_info['type'] == 'int' ? 'user' : $field_info['module'], 'user', 1);
}
return $file;
}