Uploading documents to assets folder and saving their path in database?

Any examples of this? I want to know if there is some easy way of doing than CI or its the same?

Comments

  • Maybe fiddle with this custom field?
    It turns a text field into a selector using ckfinder as the selector popup.

    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
    class MY_custom_fields {
    
       function image_selector($params) {
          $form_builder =& $params['instance'];
          if (!empty($params['value'])) {
             $params['value'] = trim($params['value'], '#');
          }
    
          $str = '';
            $preview = '';
            $asset_folder = '';
    
            if ((!isset($params['display_preview']) OR $params['display_preview'] === TRUE)) {
                if (empty($params['img_container_styles'])) {
                    $params['img_container_styles'] = 'overflow: auto; height: 200px; width: 400px; margin-top: 5px;';
                }
                if (!isset($params['img_styles'])) {
                    $params['img_styles'] = 'float: left; max-width: 200px;';
                }
    
                if (isset($params['folder']) OR isset($params['upload_path'])) {
                    if (isset($params['folder'])) {
                        $asset_folder = trim($params['folder'], '/').'/';
                        $asset_path = $asset_folder.$params['value'];
                        $asset_path = assets_path($asset_path);
                    } else {
                        $asset_folder = assets_server_to_web_path($params['upload_path']).'/';
                        $asset_path = $asset_folder.$params['value'];
                    }
    
                    if (!empty($params['replace_values'])) {
                        foreach($params['replace_values'] as $key => $val) {
                            if (is_string($val)) {
                                $asset_path = str_replace('{'.$key.'}', $val, $asset_path);
                                $asset_folder = str_replace('{'.$key.'}', $val, $asset_folder);
                            }
                        }
                    }
                }
                $preview = '';
                if (!empty($asset_path) AND !empty($params['value'])) {
                    $preview .= ' ';
                    $preview .= '<a href="'.$asset_path.'" target="_blank" class="noclone">';
                    if (isset($params['is_image']) OR (!isset($params['is_image']) AND is_image_file($asset_path))) {
                        $preview .= '<br><img src="'.$asset_path.'" style="'.$params['img_styles'].'" class="img_bg">';
                    } else {
                        $preview .= $asset_path;
                    }
                    $preview .= '</a>';
                }
            }
            $params['after_html'] = '<a href="#" onclick="'.$params['key'].'_Clear();" class="btn_field custom_ico_field"><img src="'.assets_path('_admin/ico_cancel.png').'"/></a><div id="'.$params['key'].'_preview">'.$preview.'</div>';
          setcookie('ckf_assets_isauthorized',true,time()+(7200),'/');  //If we get this far then we're in Fuel and are authorised to access Assets
          $js = '<script src="'.js_path('ckfinder','ckf_assets').'"></script>
    <script type="text/javascript">
          function '.$params['key'].'_browseserver() {
             var finder = new CKFinder();
            finder.basePath = \'./\';
            finder.selectActionFunction = '.$params['key'].'_SetFileField;
            finder.removePlugins = \'basket\';
            finder.popup();
          }
    
          function '.$params['key'].'_SetFileField( fileUrl ) {
             var f = unescape(encodeURIComponent(fileUrl.replace(jqx.config.assetsImgPath,\'\')));
            document.getElementById(\''.$params['key'].'\').value = f;
            $(\'#'.$params['key'].'_preview\').html(\'<br><img src="\'+fileUrl+\'" style="'.$params['img_styles'].'" class="img_bg">\');
            return true; //close finder
          }
    
          function '.$params['key'].'_Clear() {
             $(\'#'.$params['key'].'\').val(\'\');
             $(\'#'.$params['key'].'_preview\').html(\'\');
             return false;
          }
    </script>';
    
          $form_builder->add_js($js);
          $params['class'] = (!empty($params['class'])) ? $params['class'].' field_type_image_selector' : 'field_type_image_selector';
          $params['attributes'] = 'onclick="'.$params['key'].'_browseserver();"';
          $params['type'] = 'text';
          return '<div style="border:1px dashed #ccc;border-radius:3px;padding:10px;">'.$form_builder->create_text($params).$params['after_html'].'<div style="clear:both;"></div></div>';
          //return $str;
        }
    
    }
    
    ?>
    
  • I would like it to be done in cms page as I want my client to change however they like

  • There are a couple field types that may be able to help with your module's form:
    http://docs.getfuelcms.com/general/forms#file
    http://docs.getfuelcms.com/general/forms#asset

  • I am using CMS Forms module to create forms

  • You should be able to leverage CI's built in libraries (e.g. File Upload). If you are using the forms module, then you may want to look at a hook like post_process. The hook allows you to specify a callable function that gets executed in this case before sending out the email notification. In your form, you would want to use a file upload field and then you could process it with your function using the File Upload class.

  • I couldn't understand how can I implement post_process as I already needed to apply some styles on fields. Should I be using a controller or an extended class?
    Although right now I am using File Upload class in my controller to do this.

  • The post_process hook just needs to be callable. This means it could be a string value for a function, an array with the the object and method (e.g. array($my_object, 'my_post_process')) or a Closure function.

Sign In or Register to comment.