Skip to content

Instantly share code, notes, and snippets.

@inuvalogic
Last active August 29, 2015 14:16
Show Gist options
  • Save inuvalogic/6d1dabdb78f27df4ddeb to your computer and use it in GitHub Desktop.
Save inuvalogic/6d1dabdb78f27df4ddeb to your computer and use it in GitHub Desktop.
How to give Subdomain path in Jbimages plugin in tinymce
<?php
/* tinymce/plugins/jbimages/config.php */
| -------------------------------------------------------------------
|
| Path to upload target folder, relative to domain name. NO TRAILING SLASH!
| Example: if an image is acessed via http://www.example.com/images/somefolder/image.jpg, you should specify here:
|
| $config['img_path'] = '/images/somefolder';
|
| -------------------------------------------------------------------*/
// $config['img_path'] = '/images'; // Relative to domain name
// $config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . $config['img_path']; // Physical path. [Usually works fine like this]
$config['img_path'] = 'images/uploads';
$config['base_image_url'] = 'http://cdn.yourdomain.com/';
$config['relative_path'] = '/../cdn_public_html/';
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . $config['relative_path'] . $config['img_path'];
<?php
/* tinymce/plugins/jbimages/ci/application/controllers/uploader.php */
public function upload ($lang='english')
{
// Set language
$this->_lang_set($lang);
// Get configuartion data (we fill up 2 arrays - $config and $conf)
$conf['base_image_url'] = $this->config->item('base_image_url', 'uploader_settings');
$conf['img_path'] = $this->config->item('img_path', 'uploader_settings');
$conf['allow_resize'] = $this->config->item('allow_resize', 'uploader_settings');
$config['allowed_types'] = $this->config->item('allowed_types', 'uploader_settings');
$config['max_size'] = $this->config->item('max_size', 'uploader_settings');
$config['encrypt_name'] = $this->config->item('encrypt_name', 'uploader_settings');
$config['overwrite'] = $this->config->item('overwrite', 'uploader_settings');
$config['upload_path'] = $this->config->item('upload_path', 'uploader_settings');
if (!$conf['allow_resize'])
{
$config['max_width'] = $this->config->item('max_width', 'uploader_settings');
$config['max_height'] = $this->config->item('max_height', 'uploader_settings');
}
else
{
$conf['max_width'] = $this->config->item('max_width', 'uploader_settings');
$conf['max_height'] = $this->config->item('max_height', 'uploader_settings');
if ($conf['max_width'] == 0 and $conf['max_height'] == 0)
{
$conf['allow_resize'] = FALSE;
}
}
// Load uploader
$this->load->library('upload', $config);
if ($this->upload->do_upload()) // Success
{
// General result data
$result = $this->upload->data();
// Shall we resize an image?
if ($conf['allow_resize'] and $conf['max_width'] > 0 and $conf['max_height'] > 0 and (($result['image_width'] > $conf['max_width']) or ($result['image_height'] > $conf['max_height'])))
{
// Resizing parameters
$resizeParams = array
(
'source_image' => $result['full_path'],
'new_image' => $result['full_path'],
'width' => $conf['max_width'],
'height' => $conf['max_height']
);
// Load resize library
$this->load->library('image_lib', $resizeParams);
// Do resize
$this->image_lib->resize();
}
// Add our stuff
$result['result'] = "file_uploaded";
$result['resultcode'] = 'ok';
$result['file_name'] = $conf['base_image_url'] . $conf['img_path'] . '/' . $result['file_name'];
// Output to user
$this->load->view('ajax_upload_result', $result);
}
else // Failure
{
// Compile data for output
$result['result'] = $this->upload->display_errors(' ', ' ');
$result['resultcode'] = 'failed';
// Output to user
$this->load->view('ajax_upload_result', $result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment