SELECT ASSETS

edited May 2012 in Modules
I have a form field like the following with a simple browse button to select a file locally.

$fields['product_first_image'] = array(
'label' => '
Product Photo 1

'.$img1,
'type' => 'file',
'order' => '14',
'upload_path' =>assets_server_path('images/products/'),
'overwrite' => TRUE,
'accept'=>'jpg|jpeg|gif|tiff|png',
);

I would also like the option of the select button, once pressed you can choose a file from the assets folder also.

Thanks

Comments

  • edited 5:09AM
    Try changing the name of the field to "product_first_image_upload" but keep the field name in the database to be 'roduct_first_image'.
    $fields['product_first_image_upload'] = array( 'label' => ' Product Photo 1 '.$img1, 'type' => 'file', 'order' => '14', 'upload_path' =>assets_server_path('images/products/'), 'overwrite' => TRUE, 'accept'=>'jpg|jpeg|gif|tiff|png', );
  • edited 5:09AM
    Thanks that seems to work, problem is though..on after post i have

    $CI =& get_instance();
    $CI->load->library('image_lib');
    $delete=$this->input->post('delete');
    if($delete==false) {


    // IF AN IMAGE IS UPLOADED CREATE 2 THUMBS

    if (!empty($CI->upload)) {
    $CI->upload->data();
    foreach($this->upload_data as $data) {

    // CHECK THE PDF DELETE CHECKBOXES

    //if(!empty($data['product_installation_pdf_delete'])) { $this->db->query("UPDATE fuel_products SET product_installation_pdf=this WHERE id=63"); }

    // KEEP THE FILENAME AND THE SQL THE SAME

    if (!empty($data['full_path'])) {
    if($data['file_ext']!='.pdf') {

    // RESIZE TO PROPER 256 X 256

    // CLEAN THE ACTUAL FILE BEFORE RESIZING

    $filename = strtolower($data['file_name']);

    $config = array();
    $config['source_image'] = $data['full_path'];
    $config['create_thumb'] = FALSE;
    $config['new_image'] = assets_server_path('products/thumbs/256'.$filename, 'images');
    $config['width'] = 256;
    $config['height'] = 256;
    $config['master_dim'] = 'auto';
    $config['maintain_ratio'] = TRUE;
    $CI->image_lib->clear();
    $CI->image_lib->initialize($config);
    if (!$CI->image_lib->resize()) {
    $this->add_error($CI->image_lib->display_errors());
    }

    // CREATE 88 X 88 THUMB

    $config = array();
    $config['source_image'] = $data['full_path'];
    $config['create_thumb'] = FALSE;
    $config['new_image'] = assets_server_path('products/thumbs/88'.$filename, 'images');
    $config['width'] = 88;
    $config['height'] = 88;
    $config['master_dim'] = 'auto';
    $config['maintain_ratio'] = TRUE;
    $CI->image_lib->clear();
    $CI->image_lib->initialize($config);
    if (!$CI->image_lib->resize()) {
    $this->add_error($CI->image_lib->display_errors());
    print_r($data);


    Which creates a 88 and a 256 size of the image and pulls the data from the upload_data
    When you select a file like the above from the assets and not locally the thumbnails do not get created as the file is outside of upload_data.

    Thanks

    }
    } else {
  • edited 5:09AM
    I'm sorry but I'm not quite sure I understand the last part "When you select a file like the above from the assets and not locally the thumbnails do not get created as the file is outside of upload_data." Can you explain that a little more? Thanks.
  • edited 5:09AM
    Sorry for the bad explanation.

    OK using the code you provided did the trick, I am now able to give the user the option to either upload from their computer (locally) or use the other field ( SELECT ) to which the user can click the select button and choose a file/image from the assets folder.

    The problem I have is the code above creates 2 thumbnails, these I need. The code above takes the image from the upload_data (browse for file field) and creates 2 thumbnails. If the user decides to use the other option and select the image from the assets folder instead then the 2 thumbnails never get created because its not uploaded data. How would I create 2 thumbnails?
  • edited 5:09AM
    If this line:

    if ( ! empty($CI->upload)) {

    Is false (meaning it is empty) the path of the selected file will be in $values['product_first_image_upload'] or that may be $values['product_first_image'] sorry I don't use the assets like that.

    You can check all the posted data by doing a print_obj($_POST);
Sign In or Register to comment.