Skip to content

Instantly share code, notes, and snippets.

@alexmglover
Created May 12, 2014 00:01
Show Gist options
  • Save alexmglover/d4a943e2e2f9ec9d6492 to your computer and use it in GitHub Desktop.
Save alexmglover/d4a943e2e2f9ec9d6492 to your computer and use it in GitHub Desktop.
<?php
public function cartthrob_pre_process($options)
{
if (isset($_FILES)) {
// load the libraries and models
ee()->load->model('file_upload_preferences_model');
// get upload preferences
$uploadPrefs = ee()->file_upload_preferences_model->get_file_upload_preferences(null, 2);
$config = array(
'upload_path' => $uploadPrefs['server_path'],
'allowed_types' => '*',
'max_size' => $uploadPrefs['max_height'],
'max_width' => $uploadPrefs['max_width'],
'max_height' => $uploadPrefs['max_height'],
'overwrite' => FALSE, // default
'remove_spaces' => TRUE, // default
);
ee()->load->library('upload', $config);
if (ee()->upload->do_upload('order_po_upload'))
{
// Create thumbnail
ee()->load->library('filemanager');
ee()->load->model('file_model');
ee()->filemanager->create_thumb($uploadPrefs['server_path'] . ee()->upload->file_name, array(
'file_name' => ee()->upload->file_name,
'dimensions' => null,
'server_path' => $uploadPrefs['server_path']
));
// Save File
ee()->file_model->save_file(array(
'site_id' => ee()->config->item('site_id'),
'title' => ee()->upload->file_name,
'upload_location_id' => 2,
'rel_path' => ee()->upload->upload_path,
'mime_type' => ee()->upload->file_type,
'file_name' => ee()->upload->file_name,
'file_size' => ee()->upload->file_size,
'uploaded_by_member_id' => ee()->session->userdata['member_id'],
'upload_date' => ee()->localize->now
));
}
$_POST['order_po_upload'] = '{filedir_2}' . ee()->upload->file_name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment