CI_Upload Class Reference

List of all members.


Public Member Functions

 CI_Upload ($props=array())
 Constructor.
 initialize ($config=array())
 Initialize preferences.
 do_upload ($field= 'userfile')
 Perform the file upload.
 data ()
 Finalized Data Array.
 set_upload_path ($path)
 Set Upload Path.
 set_filename ($path, $filename)
 Set the file name.
 set_max_filesize ($n)
 Set Maximum File Size.
 set_max_filename ($n)
 Set Maximum File Name Length.
 set_max_width ($n)
 Set Maximum Image Width.
 set_max_height ($n)
 Set Maximum Image Height.
 set_allowed_types ($types)
 Set Allowed File Types.
 set_image_properties ($path= '')
 Set Image Properties.
 set_xss_clean ($flag=FALSE)
 Set XSS Clean.
 is_image ()
 Validate the image.
 is_allowed_filetype ()
 Verify that the filetype is allowed.
 is_allowed_filesize ()
 Verify that the file is within the allowed size.
 is_allowed_dimensions ()
 Verify that the image is within the allowed width/height.
 validate_upload_path ()
 Validate Upload Path.
 get_extension ($filename)
 Extract the file extension.
 clean_file_name ($filename)
 Clean the file name for security.
 limit_filename_length ($filename, $length)
 Limit the File Name Length.
 do_xss_clean ()
 Runs the file through the XSS clean function.
 set_error ($msg)
 Set an error message.
 display_errors ($open= '< p >', $close= '</p >')
 Display the error message.
 mimes_types ($mime)
 List of Mime Types.
 _prep_filename ($filename)
 Prep Filename.

Public Attributes

 $max_size = 0
 $max_width = 0
 $max_height = 0
 $max_filename = 0
 $allowed_types = ""
 $file_temp = ""
 $file_name = ""
 $orig_name = ""
 $file_type = ""
 $file_size = ""
 $file_ext = ""
 $upload_path = ""
 $overwrite = FALSE
 $encrypt_name = FALSE
 $is_image = FALSE
 $image_width = ''
 $image_height = ''
 $image_type = ''
 $image_size_str = ''
 $error_msg = array()
 $mimes = array()
 $remove_spaces = TRUE
 $xss_clean = FALSE
 $temp_prefix = "temp_file_"

Detailed Description

Definition at line 27 of file Upload.php.


Member Function Documentation

CI_Upload::_prep_filename ( filename  ) 

Prep Filename.

Prevents possible script execution from Apache's handling of files multiple extensions http://httpd.apache.org/docs/1.3/mod/mod_mime.html#multipleext

private

Parameters:
string 
Returns:
string

Definition at line 897 of file Upload.php.

References mimes_types().

Referenced by do_upload().

00898         {
00899                 if (strpos($filename, '.') === FALSE)
00900                 {
00901                         return $filename;
00902                 }
00903                 
00904                 $parts          = explode('.', $filename);
00905                 $ext            = array_pop($parts);
00906                 $filename       = array_shift($parts);
00907                                 
00908                 foreach ($parts as $part)
00909                 {
00910                         if ($this->mimes_types(strtolower($part)) === FALSE)
00911                         {
00912                                 $filename .= '.'.$part.'_';
00913                         }
00914                         else
00915                         {
00916                                 $filename .= '.'.$part;
00917                         }
00918                 }
00919                 
00920                 $filename .= '.'.$ext;
00921                 
00922                 return $filename;
00923         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Upload::CI_Upload ( props = array()  ) 

Constructor.

public

Definition at line 59 of file Upload.php.

References initialize(), and log_message().

00060         {
00061                 if (count($props) > 0)
00062                 {
00063                         $this->initialize($props);
00064                 }
00065                 
00066                 log_message('debug', "Upload Class Initialized");
00067         }

Here is the call graph for this function:

CI_Upload::clean_file_name ( filename  ) 

Clean the file name for security.

public

Parameters:
string 
Returns:
string

Definition at line 702 of file Upload.php.

Referenced by do_upload().

00703         {
00704                 $bad = array(
00705                                                 "<!--",
00706                                                 "-->",
00707                                                 "'",
00708                                                 "<",
00709                                                 ">",
00710                                                 '"',
00711                                                 '&',
00712                                                 '$',
00713                                                 '=',
00714                                                 ';',
00715                                                 '?',
00716                                                 '/',
00717                                                 "%20",
00718                                                 "%22",
00719                                                 "%3c",          // <
00720                                                 "%253c",        // <
00721                                                 "%3e",          // >
00722                                                 "%0e",          // >
00723                                                 "%28",          // (
00724                                                 "%29",          // )
00725                                                 "%2528",        // (
00726                                                 "%26",          // &
00727                                                 "%24",          // $
00728                                                 "%3f",          // ?
00729                                                 "%3b",          // ;
00730                                                 "%3d"           // =
00731                                         );
00732                                         
00733                 $filename = str_replace($bad, '', $filename);
00734 
00735                 return stripslashes($filename);
00736         }

Here is the caller graph for this function:

CI_Upload::data (  ) 

Finalized Data Array.

Returns an associative array containing all of the information related to the upload, allowing the developer easy access in one array.

public

Returns:
array

Definition at line 306 of file Upload.php.

References is_image().

00307         {
00308                 return array (
00309                                                 'file_name'                     => $this->file_name,
00310                                                 'file_type'                     => $this->file_type,
00311                                                 'file_path'                     => $this->upload_path,
00312                                                 'full_path'                     => $this->upload_path.$this->file_name,
00313                                                 'raw_name'                      => str_replace($this->file_ext, '', $this->file_name),
00314                                                 'orig_name'                     => $this->orig_name,
00315                                                 'file_ext'                      => $this->file_ext,
00316                                                 'file_size'                     => $this->file_size,
00317                                                 'is_image'                      => $this->is_image(),
00318                                                 'image_width'           => $this->image_width,
00319                                                 'image_height'          => $this->image_height,
00320                                                 'image_type'            => $this->image_type,
00321                                                 'image_size_str'        => $this->image_size_str,
00322                                         );
00323         }

Here is the call graph for this function:

CI_Upload::display_errors ( open = '<p>',
close = '</p>' 
)

Display the error message.

public

Parameters:
string 
string 
Returns:
string

Definition at line 846 of file Upload.php.

00847         {
00848                 $str = '';
00849                 foreach ($this->error_msg as $val)
00850                 {
00851                         $str .= $open.$val.$close;
00852                 }
00853         
00854                 return $str;
00855         }

CI_Upload::do_upload ( field = 'userfile'  ) 

Perform the file upload.

public

Returns:
bool

Definition at line 137 of file Upload.php.

References _prep_filename(), clean_file_name(), do_xss_clean(), get_extension(), is_allowed_dimensions(), is_allowed_filesize(), is_allowed_filetype(), limit_filename_length(), set_error(), set_filename(), set_image_properties(), and validate_upload_path().

00138         {
00139                 // Is $_FILES[$field] set? If not, no reason to continue.
00140                 if ( ! isset($_FILES[$field]))
00141                 {
00142                         $this->set_error('upload_no_file_selected');
00143                         return FALSE;
00144                 }
00145                 
00146                 // Is the upload path valid?
00147                 if ( ! $this->validate_upload_path())
00148                 {
00149                         // errors will already be set by validate_upload_path() so just return FALSE
00150                         return FALSE;
00151                 }
00152 
00153                 // Was the file able to be uploaded? If not, determine the reason why.
00154                 if ( ! is_uploaded_file($_FILES[$field]['tmp_name']))
00155                 {
00156                         $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error'];
00157 
00158                         switch($error)
00159                         {
00160                                 case 1: // UPLOAD_ERR_INI_SIZE
00161                                         $this->set_error('upload_file_exceeds_limit');
00162                                         break;
00163                                 case 2: // UPLOAD_ERR_FORM_SIZE
00164                                         $this->set_error('upload_file_exceeds_form_limit');
00165                                         break;
00166                                 case 3: // UPLOAD_ERR_PARTIAL
00167                                    $this->set_error('upload_file_partial');
00168                                         break;
00169                                 case 4: // UPLOAD_ERR_NO_FILE
00170                                    $this->set_error('upload_no_file_selected');
00171                                         break;
00172                                 case 6: // UPLOAD_ERR_NO_TMP_DIR
00173                                         $this->set_error('upload_no_temp_directory');
00174                                         break;
00175                                 case 7: // UPLOAD_ERR_CANT_WRITE
00176                                         $this->set_error('upload_unable_to_write_file');
00177                                         break;
00178                                 case 8: // UPLOAD_ERR_EXTENSION
00179                                         $this->set_error('upload_stopped_by_extension');
00180                                         break;
00181                                 default :   $this->set_error('upload_no_file_selected');
00182                                         break;
00183                         }
00184 
00185                         return FALSE;
00186                 }
00187 
00188                 // Set the uploaded data as class variables
00189                 $this->file_temp = $_FILES[$field]['tmp_name'];         
00190                 $this->file_name = $this->_prep_filename($_FILES[$field]['name']);
00191                 $this->file_size = $_FILES[$field]['size'];             
00192                 $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']);
00193                 $this->file_type = strtolower($this->file_type);
00194                 $this->file_ext  = $this->get_extension($_FILES[$field]['name']);
00195                 
00196                 // Convert the file size to kilobytes
00197                 if ($this->file_size > 0)
00198                 {
00199                         $this->file_size = round($this->file_size/1024, 2);
00200                 }
00201 
00202                 // Is the file type allowed to be uploaded?
00203                 if ( ! $this->is_allowed_filetype())
00204                 {
00205                         $this->set_error('upload_invalid_filetype');
00206                         return FALSE;
00207                 }
00208 
00209                 // Is the file size within the allowed maximum?
00210                 if ( ! $this->is_allowed_filesize())
00211                 {
00212                         $this->set_error('upload_invalid_filesize');
00213                         return FALSE;
00214                 }
00215 
00216                 // Are the image dimensions within the allowed size?
00217                 // Note: This can fail if the server has an open_basdir restriction.
00218                 if ( ! $this->is_allowed_dimensions())
00219                 {
00220                         $this->set_error('upload_invalid_dimensions');
00221                         return FALSE;
00222                 }
00223 
00224                 // Sanitize the file name for security
00225                 $this->file_name = $this->clean_file_name($this->file_name);
00226                 
00227                 // Truncate the file name if it's too long
00228                 if ($this->max_filename > 0)
00229                 {
00230                         $this->file_name = $this->limit_filename_length($this->file_name, $this->max_filename);
00231                 }
00232 
00233                 // Remove white spaces in the name
00234                 if ($this->remove_spaces == TRUE)
00235                 {
00236                         $this->file_name = preg_replace("/\s+/", "_", $this->file_name);
00237                 }
00238 
00239                 /*
00240                  * Validate the file name
00241                  * This function appends an number onto the end of
00242                  * the file if one with the same name already exists.
00243                  * If it returns false there was a problem.
00244                  */
00245                 $this->orig_name = $this->file_name;
00246 
00247                 if ($this->overwrite == FALSE)
00248                 {
00249                         $this->file_name = $this->set_filename($this->upload_path, $this->file_name);
00250                         
00251                         if ($this->file_name === FALSE)
00252                         {
00253                                 return FALSE;
00254                         }
00255                 }
00256 
00257                 /*
00258                  * Move the file to the final destination
00259                  * To deal with different server configurations
00260                  * we'll attempt to use copy() first.  If that fails
00261                  * we'll use move_uploaded_file().  One of the two should
00262                  * reliably work in most environments
00263                  */
00264                 if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name))
00265                 {
00266                         if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name))
00267                         {
00268                                  $this->set_error('upload_destination_error');
00269                                  return FALSE;
00270                         }
00271                 }
00272                 
00273                 /*
00274                  * Run the file through the XSS hacking filter
00275                  * This helps prevent malicious code from being
00276                  * embedded within a file.  Scripts can easily
00277                  * be disguised as images or other file types.
00278                  */
00279                 if ($this->xss_clean == TRUE)
00280                 {
00281                         $this->do_xss_clean();
00282                 }
00283 
00284                 /*
00285                  * Set the finalized image dimensions
00286                  * This sets the image width/height (assuming the
00287                  * file was an image).  We use this information
00288                  * in the "data" function.
00289                  */
00290                 $this->set_image_properties($this->upload_path.$this->file_name);
00291 
00292                 return TRUE;
00293         }

Here is the call graph for this function:

CI_Upload::do_xss_clean (  ) 

Runs the file through the XSS clean function.

This prevents people from embedding malicious code in their files. I'm not sure that it won't negatively affect certain files in unexpected ways, but so far I haven't found that it causes trouble.

public

Returns:
void

Definition at line 777 of file Upload.php.

References $CI, and get_instance().

Referenced by do_upload().

00778         {               
00779                 $file = $this->upload_path.$this->file_name;
00780                 
00781                 if (filesize($file) == 0)
00782                 {
00783                         return FALSE;
00784                 }
00785 
00786                 if (($data = @file_get_contents($file)) === FALSE)
00787                 {
00788                         return FALSE;
00789                 }
00790                 
00791                 if ( ! $fp = @fopen($file, FOPEN_READ_WRITE))
00792                 {
00793                         return FALSE;
00794                 }
00795 
00796                 $CI =& get_instance();  
00797                 $data = $CI->input->xss_clean($data);
00798                 
00799                 flock($fp, LOCK_EX);
00800                 fwrite($fp, $data);
00801                 flock($fp, LOCK_UN);
00802                 fclose($fp);
00803         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Upload::get_extension ( filename  ) 

Extract the file extension.

public

Parameters:
string 
Returns:
string

Definition at line 687 of file Upload.php.

Referenced by do_upload().

00688         {
00689                 $x = explode('.', $filename);
00690                 return '.'.end($x);
00691         }       

Here is the caller graph for this function:

CI_Upload::initialize ( config = array()  ) 

Initialize preferences.

public

Parameters:
array 
Returns:
void

Definition at line 78 of file Upload.php.

References $config, and $method.

Referenced by CI_Upload().

00079         {
00080                 $defaults = array(
00081                                                         'max_size'                      => 0,
00082                                                         'max_width'                     => 0,
00083                                                         'max_height'            => 0,
00084                                                         'max_filename'          => 0,
00085                                                         'allowed_types'         => "",
00086                                                         'file_temp'                     => "",
00087                                                         'file_name'                     => "",
00088                                                         'orig_name'                     => "",
00089                                                         'file_type'                     => "",
00090                                                         'file_size'                     => "",
00091                                                         'file_ext'                      => "",
00092                                                         'upload_path'           => "",
00093                                                         'overwrite'                     => FALSE,
00094                                                         'encrypt_name'          => FALSE,
00095                                                         'is_image'                      => FALSE,
00096                                                         'image_width'           => '',
00097                                                         'image_height'          => '',
00098                                                         'image_type'            => '',
00099                                                         'image_size_str'        => '',
00100                                                         'error_msg'                     => array(),
00101                                                         'mimes'                         => array(),
00102                                                         'remove_spaces'         => TRUE,
00103                                                         'xss_clean'                     => FALSE,
00104                                                         'temp_prefix'           => "temp_file_"
00105                                                 );      
00106         
00107         
00108                 foreach ($defaults as $key => $val)
00109                 {
00110                         if (isset($config[$key]))
00111                         {
00112                                 $method = 'set_'.$key;
00113                                 if (method_exists($this, $method))
00114                                 {
00115                                         $this->$method($config[$key]);
00116                                 }
00117                                 else
00118                                 {
00119                                         $this->$key = $config[$key];
00120                                 }                       
00121                         }
00122                         else
00123                         {
00124                                 $this->$key = $val;
00125                         }
00126                 }
00127         }

Here is the caller graph for this function:

CI_Upload::is_allowed_dimensions (  ) 

Verify that the image is within the allowed width/height.

public

Returns:
bool

Definition at line 611 of file Upload.php.

References is_image().

Referenced by do_upload().

00612         {
00613                 if ( ! $this->is_image())
00614                 {
00615                         return TRUE;
00616                 }
00617 
00618                 if (function_exists('getimagesize'))
00619                 {
00620                         $D = @getimagesize($this->file_temp);
00621 
00622                         if ($this->max_width > 0 AND $D['0'] > $this->max_width)
00623                         {
00624                                 return FALSE;
00625                         }
00626 
00627                         if ($this->max_height > 0 AND $D['1'] > $this->max_height)
00628                         {
00629                                 return FALSE;
00630                         }
00631 
00632                         return TRUE;
00633                 }
00634 
00635                 return TRUE;
00636         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Upload::is_allowed_filesize (  ) 

Verify that the file is within the allowed size.

public

Returns:
bool

Definition at line 591 of file Upload.php.

Referenced by do_upload().

00592         {
00593                 if ($this->max_size != 0  AND  $this->file_size > $this->max_size)
00594                 {
00595                         return FALSE;
00596                 }
00597                 else
00598                 {
00599                         return TRUE;
00600                 }
00601         }

Here is the caller graph for this function:

CI_Upload::is_allowed_filetype (  ) 

Verify that the filetype is allowed.

public

Returns:
bool

Definition at line 552 of file Upload.php.

References mimes_types(), and set_error().

Referenced by do_upload().

00553         {
00554                 if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types))
00555                 {
00556                         $this->set_error('upload_no_file_types');
00557                         return FALSE;
00558                 }
00559                                 
00560                 foreach ($this->allowed_types as $val)
00561                 {
00562                         $mime = $this->mimes_types(strtolower($val));
00563                 
00564                         if (is_array($mime))
00565                         {
00566                                 if (in_array($this->file_type, $mime, TRUE))
00567                                 {
00568                                         return TRUE;
00569                                 }
00570                         }
00571                         else
00572                         {
00573                                 if ($mime == $this->file_type)
00574                                 {
00575                                         return TRUE;
00576                                 }       
00577                         }               
00578                 }
00579                 
00580                 return FALSE;
00581         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Upload::is_image (  ) 

Validate the image.

public

Returns:
bool

Definition at line 517 of file Upload.php.

Referenced by data(), is_allowed_dimensions(), and set_image_properties().

00518         {
00519                 // IE will sometimes return odd mime-types during upload, so here we just standardize all
00520                 // jpegs or pngs to the same file type.
00521 
00522                 $png_mimes  = array('image/x-png');
00523                 $jpeg_mimes = array('image/jpg', 'image/jpe', 'image/jpeg', 'image/pjpeg');
00524                 
00525                 if (in_array($this->file_type, $png_mimes))
00526                 {
00527                         $this->file_type = 'image/png';
00528                 }
00529                 
00530                 if (in_array($this->file_type, $jpeg_mimes))
00531                 {
00532                         $this->file_type = 'image/jpeg';
00533                 }
00534 
00535                 $img_mimes = array(
00536                                                         'image/gif',
00537                                                         'image/jpeg',
00538                                                         'image/png',
00539                                                    );
00540 
00541                 return (in_array($this->file_type, $img_mimes, TRUE)) ? TRUE : FALSE;
00542         }

Here is the caller graph for this function:

CI_Upload::limit_filename_length ( filename,
length 
)

Limit the File Name Length.

public

Parameters:
string 
Returns:
string

Definition at line 747 of file Upload.php.

Referenced by do_upload().

00748         {
00749                 if (strlen($filename) < $length)
00750                 {
00751                         return $filename;
00752                 }
00753         
00754                 $ext = '';
00755                 if (strpos($filename, '.') !== FALSE)
00756                 {
00757                         $parts          = explode('.', $filename);
00758                         $ext            = '.'.array_pop($parts);
00759                         $filename       = implode('.', $parts);
00760                 }
00761         
00762                 return substr($filename, 0, ($length - strlen($ext))).$ext;
00763         }

Here is the caller graph for this function:

CI_Upload::mimes_types ( mime  ) 

List of Mime Types.

This is a list of mime types. We use it to validate the "allowed types" set by the developer

public

Parameters:
string 
Returns:
string

Definition at line 869 of file Upload.php.

References $mimes.

Referenced by _prep_filename(), and is_allowed_filetype().

00870         {
00871                 global $mimes;
00872         
00873                 if (count($this->mimes) == 0)
00874                 {
00875                         if (@require_once(APPPATH.'config/mimes'.EXT))
00876                         {
00877                                 $this->mimes = $mimes;
00878                                 unset($mimes);
00879                         }
00880                 }
00881         
00882                 return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime];
00883         }

Here is the caller graph for this function:

CI_Upload::set_allowed_types ( types  ) 

Set Allowed File Types.

public

Parameters:
string 
Returns:
void

Definition at line 455 of file Upload.php.

00456         {
00457                 $this->allowed_types = explode('|', $types);
00458         }

CI_Upload::set_error ( msg  ) 

Set an error message.

public

Parameters:
string 
Returns:
void

Definition at line 814 of file Upload.php.

References $CI, get_instance(), and log_message().

Referenced by do_upload(), is_allowed_filetype(), set_filename(), and validate_upload_path().

00815         {
00816                 $CI =& get_instance();  
00817                 $CI->lang->load('upload');
00818                 
00819                 if (is_array($msg))
00820                 {
00821                         foreach ($msg as $val)
00822                         {
00823                                 $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val);                         
00824                                 $this->error_msg[] = $msg;
00825                                 log_message('error', $msg);
00826                         }               
00827                 }
00828                 else
00829                 {
00830                         $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg);
00831                         $this->error_msg[] = $msg;
00832                         log_message('error', $msg);
00833                 }
00834         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Upload::set_filename ( path,
filename 
)

Set the file name.

This function takes a filename/path as input and looks for the existence of a file with the same name. If found, it will append a number to the end of the filename to avoid overwriting a pre-existing file.

public

Parameters:
string 
string 
Returns:
string

Definition at line 354 of file Upload.php.

References set_error().

Referenced by do_upload().

00355         {
00356                 if ($this->encrypt_name == TRUE)
00357                 {               
00358                         mt_srand();
00359                         $filename = md5(uniqid(mt_rand())).$this->file_ext;     
00360                 }
00361         
00362                 if ( ! file_exists($path.$filename))
00363                 {
00364                         return $filename;
00365                 }
00366         
00367                 $filename = str_replace($this->file_ext, '', $filename);
00368                 
00369                 $new_filename = '';
00370                 for ($i = 1; $i < 100; $i++)
00371                 {                       
00372                         if ( ! file_exists($path.$filename.$i.$this->file_ext))
00373                         {
00374                                 $new_filename = $filename.$i.$this->file_ext;
00375                                 break;
00376                         }
00377                 }
00378 
00379                 if ($new_filename == '')
00380                 {
00381                         $this->set_error('upload_bad_filename');
00382                         return FALSE;
00383                 }
00384                 else
00385                 {
00386                         return $new_filename;
00387                 }
00388         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Upload::set_image_properties ( path = ''  ) 

Set Image Properties.

Uses GD to determine the width/height/type of image

public

Parameters:
string 
Returns:
void

Definition at line 471 of file Upload.php.

References is_image().

Referenced by do_upload().

00472         {
00473                 if ( ! $this->is_image())
00474                 {
00475                         return;
00476                 }
00477 
00478                 if (function_exists('getimagesize'))
00479                 {
00480                         if (FALSE !== ($D = @getimagesize($path)))
00481                         {       
00482                                 $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png');
00483 
00484                                 $this->image_width              = $D['0'];
00485                                 $this->image_height             = $D['1'];
00486                                 $this->image_type               = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']];
00487                                 $this->image_size_str   = $D['3'];  // string containing height and width
00488                         }
00489                 }
00490         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Upload::set_max_filename ( n  ) 

Set Maximum File Name Length.

public

Parameters:
integer 
Returns:
void

Definition at line 413 of file Upload.php.

00414         {
00415                 $this->max_filename = ((int) $n < 0) ? 0: (int) $n;
00416         }

CI_Upload::set_max_filesize ( n  ) 

Set Maximum File Size.

public

Parameters:
integer 
Returns:
void

Definition at line 399 of file Upload.php.

00400         {
00401                 $this->max_size = ((int) $n < 0) ? 0: (int) $n;
00402         }

CI_Upload::set_max_height ( n  ) 

Set Maximum Image Height.

public

Parameters:
integer 
Returns:
void

Definition at line 441 of file Upload.php.

00442         {
00443                 $this->max_height = ((int) $n < 0) ? 0: (int) $n;
00444         }

CI_Upload::set_max_width ( n  ) 

Set Maximum Image Width.

public

Parameters:
integer 
Returns:
void

Definition at line 427 of file Upload.php.

00428         {
00429                 $this->max_width = ((int) $n < 0) ? 0: (int) $n;
00430         }

CI_Upload::set_upload_path ( path  ) 

Set Upload Path.

public

Parameters:
string 
Returns:
void

Definition at line 334 of file Upload.php.

00335         {
00336                 // Make sure it has a trailing slash
00337                 $this->upload_path = rtrim($path, '/').'/';
00338         }

CI_Upload::set_xss_clean ( flag = FALSE  ) 

Set XSS Clean.

Enables the XSS flag so that the file that was uploaded will be run through the XSS filter.

public

Parameters:
bool 
Returns:
void

Definition at line 504 of file Upload.php.

00505         {
00506                 $this->xss_clean = ($flag == TRUE) ? TRUE : FALSE;
00507         }

CI_Upload::validate_upload_path (  ) 

Validate Upload Path.

Verifies that it is a valid upload path with proper permissions.

public

Returns:
bool

Definition at line 649 of file Upload.php.

References is_really_writable(), and set_error().

Referenced by do_upload().

00650         {
00651                 if ($this->upload_path == '')
00652                 {
00653                         $this->set_error('upload_no_filepath');
00654                         return FALSE;
00655                 }
00656                 
00657                 if (function_exists('realpath') AND @realpath($this->upload_path) !== FALSE)
00658                 {
00659                         $this->upload_path = str_replace("\\", "/", realpath($this->upload_path));
00660                 }
00661 
00662                 if ( ! @is_dir($this->upload_path))
00663                 {
00664                         $this->set_error('upload_no_filepath');
00665                         return FALSE;
00666                 }
00667 
00668                 if ( ! is_really_writable($this->upload_path))
00669                 {
00670                         $this->set_error('upload_not_writable');
00671                         return FALSE;
00672                 }
00673 
00674                 $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/",  $this->upload_path);
00675                 return TRUE;
00676         }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

CI_Upload::$allowed_types = ""

Definition at line 33 of file Upload.php.

CI_Upload::$encrypt_name = FALSE

Definition at line 42 of file Upload.php.

CI_Upload::$error_msg = array()

Definition at line 48 of file Upload.php.

CI_Upload::$file_ext = ""

Definition at line 39 of file Upload.php.

CI_Upload::$file_name = ""

Definition at line 35 of file Upload.php.

CI_Upload::$file_size = ""

Definition at line 38 of file Upload.php.

CI_Upload::$file_temp = ""

Definition at line 34 of file Upload.php.

CI_Upload::$file_type = ""

Definition at line 37 of file Upload.php.

CI_Upload::$image_height = ''

Definition at line 45 of file Upload.php.

CI_Upload::$image_size_str = ''

Definition at line 47 of file Upload.php.

CI_Upload::$image_type = ''

Definition at line 46 of file Upload.php.

CI_Upload::$image_width = ''

Definition at line 44 of file Upload.php.

CI_Upload::$is_image = FALSE

Definition at line 43 of file Upload.php.

CI_Upload::$max_filename = 0

Definition at line 32 of file Upload.php.

CI_Upload::$max_height = 0

Definition at line 31 of file Upload.php.

CI_Upload::$max_size = 0

Definition at line 29 of file Upload.php.

CI_Upload::$max_width = 0

Definition at line 30 of file Upload.php.

CI_Upload::$mimes = array()

Definition at line 49 of file Upload.php.

Referenced by mimes_types().

CI_Upload::$orig_name = ""

Definition at line 36 of file Upload.php.

CI_Upload::$overwrite = FALSE

Definition at line 41 of file Upload.php.

CI_Upload::$remove_spaces = TRUE

Definition at line 50 of file Upload.php.

CI_Upload::$temp_prefix = "temp_file_"

Definition at line 52 of file Upload.php.

CI_Upload::$upload_path = ""

Definition at line 40 of file Upload.php.

CI_Upload::$xss_clean = FALSE

Definition at line 51 of file Upload.php.


The documentation for this class was generated from the following file: