Welcome Guest, Not a member yet? Register   Sign In
  Upload Class x Swfupload
Posted by: El Forum - 07-18-2008, 08:44 PM - No Replies

[eluser]slith[/eluser]
While trying to use swfupload with the CI Upload class I had 'jpg|jpeg' as valid file types. however i kept getting an error telling me me invalid file type when uploading jpeg images.

I then tried extending the upload class as mention in the forum topic 79115 and 80481 but then i kept getting the invalid path error.

i realized the problem was with is_allowed_filetype() in the Upload class where $this->file_type was recognizing my image as 'application/octet-stream'. i figure this has something to do with how swfupload handles uploads.

so to get around this problem, i simply edited config/mimes.php file and added 'application/octet-stream' to jpg and now it works.

Code:
'jpeg'    =>    array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'jpg'    =>    array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),

this may not be the proper way to fix this so if anybody has a better solution please let me know.

Thanks!


  I have extended Controller, how to use a function in view files?
Posted by: El Forum - 07-18-2008, 08:27 PM - Replies (2)

[eluser]loathsome[/eluser]
Hi there.

I have extended the Controller class (with BaseController), and I have a custom _load function in that.

When I do this:

Code:
class Dummy extends BaseController {

function index(){
parent::_load('blabla', false);
}

}

Everything works as it should Smile The loader loads up a "load file" which then loads up a normal view file. The problem is, how can i use the _load function WITHIN one of my view files? Say I wanted to do this

Code:
<h2>Hello</h2>
&lt;?php parent::_load('blabla', false);

Though, that doesnt work.

Thanks!


  AutoValidate v0.01
Posted by: El Forum - 07-18-2008, 06:18 PM - Replies (1)

[eluser]Pygon[/eluser]
The more and more I played with Struts, the more I LOVED the idea of being able to automatically validate the input without needing to call functions, and being able to separate validation rules into files, as well as having a sort of tiered validation that allows validation at a controller or method level (or both).

As I toyed with a similar implementation for CI, I found that full automation wasn't the best solution, so I went for simplification:

NOTE: If you have not fixed index.php faux-absolute-junk it does for apppath/basepath, you will probably need to disable the security, and this hasn't exactly been tested in this way.

File: /application/libraries/Autovalidate.php

Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Autovalidate {
    var $CI;
    var $_validation_dir;
    var $_validation_suffix = "_validation";
    var $_validation_security = TRUE;

    function Autovalidate()
    {
        $this->CI = &get;_instance();
        if( empty($this->CI->validation) ) $this->CI->load->library('validation');
        
        $dir = $this->CI->config->item('validation_directory');
        if(empty($dir)) $dir = "validation/";
        $this->set_validation_dir($dir);
    
        $security = $this->CI->config->item('validation_security');
        if($security) $this->_validation_security = $security;
        
        $suffix = $this->CI->config->item('validation_suffix');
        if($suffix) $this->_validation_suffix = $suffix;
        
        log_message('debug', "Validation Class Initialized");
    }
    
    function set_validation_dir($dir,$append=false)
    {
        if(empty($dir)) return;
        
        $dir = str_replace('\\','/',$dir);

        $dir = $append ? realpath($this->_validation_dir . $dir) : realpath(APPPATH . $dir);
        $this->_validation_dir = str_replace('\\','/',$dir);
        
        if(empty($this->_validation_dir) || !is_dir($this->_validation_dir)){
            show_error("Validation Error: The setting for validation directory is incorrect or the directory is missing.");
        } else if($this->_validation_security && strstr($this->_validation_dir,APPPATH) === FALSE) {
            show_error("Validation Security: This validation directory is incorrect or outside the application directory.");
        }
    }
    
    function validate_input($controller, $method=null){
        //Try base controller validation
        if( $this->_load_validation($controller . $this->_validation_suffix . EXT) === FALSE ) return false;
        
        //Try method specific validation
        if( !empty($method) && $this->_load_validation($controller.'_'.$method . $this->_validation_suffix . EXT) === FALSE ) return false;
        
        return true;
    }
    
    function _load_validation($file)
    {
        if( file_exists($this->_validation_dir.$file) ){
            
            include_once($this->_validation_dir.$file);
            if(!empty($rules)) $this->CI->validation->set_rules($rules);
            if(!empty($fields)) $this->CI->validation->set_fields($fields);
            return $this->CI->validation->run();
        }
        return true;
    }    
    
}

/application/config/config.php (optional)
Code:
/*
|--------------------------------------------------------------------------
| Validation Directory
|--------------------------------------------------------------------------
|
| This is the directory (in the application folder) to locate the validation
| files in. Should end with a '/'.
|
*/
$config['validation_directory'] = 'validation/';

/*
|--------------------------------------------------------------------------
| Validation Security
|--------------------------------------------------------------------------
|
| This flag enables or disables the validation security which verifies
| that the directory for validation files is not outside the application
| directory.
|
*/
$config['validation_security'] = TRUE;

/*
|--------------------------------------------------------------------------
| Validation File Suffix
|--------------------------------------------------------------------------
|
| This sets the suffix of the files that will be used for validation
| (in case you choose to put these files inside your controller directory).
|
*/
$config['validation_suffix'] = "_validation";

set_validation_dir - sets the directory to use for validation files. Useful if you want to set a different directory for a controller or method. Setting the second parameter to TRUE will append the directory to the existing.
Example:
Code:
set_validation_dir("validate/");
// equates to path/to/application/validate/

set_validation_dir("controller/",TRUE);
//equates to path/to/application/validate/controller/

validate_input - takes two parameters (controller name, method name [optional]). Calling this will automatically load the validation files and run the validation. First "controller" validation will be loaded, then "controller_method" validation if passed. Returns TRUE if passed, FALSE if failed. Errors are available in the standard fashion by calling $this->validation library (which is autoloaded if it does not exist when loading autovalidate).


Example Usage (default configuration)
Code:
// application/controller/test.php
//a standard CI controller with autovalidate loaded.
function submit()
{
  if(!$this->autovalidate->validate_input('test','submit')){
    //test_form.html is a simple form with a text field for submission
    $this->load->view('test_form.html');
    echo 'Failed Validation.<br />';
    return;
  }
   echo 'Passed!';
}

// application/validation/test_validation.php
$rules['testing'] = "min_length[5]|max_length[128]";
$fields['testing']    = 'Testing';

// application/validation/test_submit_validation.php
$rules['testing'] = "required";


  index.php - Defined Constants not Absolute [with fix]
Posted by: El Forum - 07-18-2008, 05:35 PM - Replies (7)

[eluser]Pygon[/eluser]
The more I have to come back to this thing, the more annoyed I get.

Code:
/*
|---------------------------------------------------------------
| SET THE SERVER PATH
|---------------------------------------------------------------
|
| Let's attempt to determine the full-server path to the "system"
| folder in order to reduce the possibility of path problems.
| Note: We only attempt this if the user hasn't specified a
| full server path.
|
*/
if (strpos($system_folder, '/') === FALSE)
{
    if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE)
    {
        $system_folder = realpath(dirname(__FILE__)).'/'.$system_folder;
    }
}
else
{
    // Swap directory separators to Unix style for consistency
    $system_folder = str_replace("\\", "/", $system_folder);
}

/*
|---------------------------------------------------------------
| DEFINE APPLICATION CONSTANTS
|---------------------------------------------------------------
|
| EXT        - The file extension.  Typically ".php"
| FCPATH    - The full server path to THIS file
| SELF        - The name of THIS file (typically "index.php)
| BASEPATH    - The full server path to the "system" folder
| APPPATH    - The full server path to the "application" folder
|
*/
define('EXT', '.'.pathinfo(__FILE__, PATHINFO_EXTENSION));
define('FCPATH', __FILE__);
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
define('BASEPATH', $system_folder.'/');

if (is_dir($application_folder))
{
    define('APPPATH', $application_folder.'/');
}
else
{
    if ($application_folder == '')
    {
        $application_folder = 'application';
    }

    define('APPPATH', BASEPATH.$application_folder.'/');
}


First and foremost, the APPPATH is defined as:
" APPPATH - The full server path to the "application" folder "

Unfortunately, this is untrue:
Code:
define('APPPATH', $application_folder.'/'); //relative path
and:
Code:
define('APPPATH', BASEPATH.$application_folder.'/'); //an "almost" absolute path.

Second:
There is some seriously terrible stuff going on with the setting of $system_folder, such as checking if realpath is a function (has been for a LONG time), using strpos('/') to determine if it's an "absolute" path ("./something" is not ABSOLUTE path...) and using realpath(dirname()) (err why?)*.

Look, I'm not saying this code is terrible (I'm atleast not trying to be insulting by saying this), I'm wondering, why is this STILL like this?

I use this for real absolute paths:
Code:
/*
|---------------------------------------------------------------
| SET THE SERVER PATH
|---------------------------------------------------------------
|
| Let's attempt to determine the full server path to the "system"
| folder in order to reduce the possibility of path problems.
|
*/
$system_folder = str_replace('\\','/',realpath($system_folder));
if(!$system_folder)
{
    //Try the default
    $system_folder = str_replace('\\','/',realpath(__FILE__).'/system');
}
if(!is_dir($system_folder))
{
    die('Invalid system folder specified. Please check your $system_folder setting.');
}

/*
|---------------------------------------------------------------
| SET THE APPLICATION PATH
|---------------------------------------------------------------
|
| Let's attempt to determine the full system path to the "application"
| folder in order to reduce the possibility of path problems.
|
*/
$application_folder = str_replace('\\','/',realpath($application_folder));
if(!$application_folder)
{
    //Try the default
    $application_folder = str_replace('\\','/',realpath(BASEPATH.'application'));
}
if(!is_dir($application_folder))
{
    die('Invalid system folder specified. Please check your $system_folder setting.');
}


/*
|---------------------------------------------------------------
| DEFINE APPLICATION CONSTANTS
|---------------------------------------------------------------
|
| EXT        - The file extension.  Typically ".php"
| FCPATH    - The full server path to THIS file
| SELF        - The name of THIS file (typically "index.php)
| BASEPATH    - The full server path to the "system" folder
| APPPATH    - The full server path to the "application" folder
|
*/
define('EXT', '.'.pathinfo(__FILE__, PATHINFO_EXTENSION));
define('FCPATH', __FILE__);
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
define('BASEPATH', $system_folder.'/');
define('APPPATH',$application_folder.'/');

*inparo has pointed this out to be my error.


  What are you guys using for deployment?
Posted by: El Forum - 07-18-2008, 05:25 PM - Replies (8)

[eluser]cbmeeks[/eluser]
To increase security, I've removed root login from SSH, changed the SSH port, etc.

But now, it's become annoying trying to transfer files from my local dev server to production.

I have to sftp to a non-root account. ssh in. su to root. and "mv" files to the right folder.

Any better solutions?

Thanks


  validate upload ??
Posted by: El Forum - 07-18-2008, 04:25 PM - Replies (1)

[eluser]Asinox[/eluser]
How i ll validate that upload form?, not empty?

Thanks


  Equavalent of Cake "Elements"
Posted by: El Forum - 07-18-2008, 02:34 PM - Replies (3)

[eluser]august.gresens[/eluser]
Hello

I'm a recent convert to CI, having abandoned the intricacies of CakePHP for something a bit more transparent.

There are a few features I miss, one being the "Elements" construct.

I'm sure there is an easy way to do the same thing in CI.

Do I just use include directives?

Thanks,

August


  is making the CI super object a global varible instead of referencing it with $this a security hole
Posted by: El Forum - 07-18-2008, 02:30 PM - Replies (2)

[eluser]Sally D[/eluser]
I was fooling around and I made a code igniter library that evaluates a 5 card poker hand. Should I be using the $this->CI instead. What kind of security hole happens if I make it global to the function that needs it? It's a lot easier then typing $this->Ci all the that's why



Code:
// or should I reference the ci super object that I create in my library functions with the $this-> //key word
    function score_hand(){
        global $CI;
        if($CI->eval_hand->royal_flush()) {
                echo "royal flush";
                $this->cash+=1000;
                return;
            } else if($CI->eval_hand->straight_flush()) {
                echo "straight flush";
                $this->cash+=500;
                return;
            } else if($CI->eval_hand->four_of_a_kind()) {
                echo "four of a kind";
                $this->cash+=400;
                return;
            } else if($CI->eval_hand->full_house()){
                echo "full house";
                $this->cash+=300;
                return;
            } else if($CI->eval_hand->flush()) {
                echo "flush";
                $this->cash+=275;
                return;
            } else if($CI->eval_hand->straight()){
                echo "straight";
                $this->cash+=250;
                return;
            } else if($CI->eval_hand->three_of_a_kind()){
                echo "three of a kind";
                $this->cash+=120;
                return;
            } else if($CI->eval_hand->two_pair()){
                echo "two pair";
                $this->cash+=40;
                return;
                
                
            } else if($CI->eval_hand->pair()){
                
                echo "pair";
                $this->cash+=20;
                //echo $this->cash;
                return;
            } else {
                               echo "make a hi card algorithm";
                               return;
                        }
            
    }


  htaccess problem
Posted by: El Forum - 07-18-2008, 01:38 PM - No Replies

[eluser]emperius[/eluser]
I have a site where I changed a source code and made it in codeigniter.Now I have to make 301 redirect to keep the links from the old site working.

The following problem have appeared: I see no way to transfer all the pages index.php?type=allnews to /news/ even if there are more parameters after 'allnews'


  another htaccess problem
Posted by: El Forum - 07-18-2008, 01:29 PM - Replies (2)

[eluser]emperius[/eluser]
I have a site where I changed a source code and made it in codeigniter.Now I have to make 301 redirect to keep the links from the old site working.

The following problem have appeared: I see no way to transfer all the pages index.php?type=allnews to /news/ even if there are more parameters after 'allnews'


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
Optimize.php make a probl...
by ALTITUDE_DEV
5 hours ago
4.4.1 to 4.4.8 base_url p...
by xsPurX
7 hours ago
How to make nav-link acti...
by Tokioshy
Today, 06:19 AM
Cannot access protected p...
by mywebmanavgat
Today, 05:25 AM
custom validation dinamic
by ozornick
Today, 05:12 AM
QueryBuilder inside
by objecttothis
Today, 04:35 AM
DataCaster not working
by kenjis
Today, 03:16 AM
Querybuilder select() par...
by objecttothis
Today, 12:33 AM
Ci4, CLI Spark Run Standa...
by dhiya as
Today, 12:08 AM
auth() differs from my lo...
by JohnUK
Yesterday, 10:45 PM

Forum Statistics
» Members: 86,579
» Latest member: shbetvc
» Forum threads: 77,618
» Forum posts: 376,189

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB