EllisLab text mark
Advanced Search
     
Codeigniter 2.1 - file upload, character replace
Posted: 10 November 2012 12:43 PM   [ Ignore ]
Joined: 2011-08-23
24 posts

I have this to functions:

This one is for image upload:

function img_upload($folder{
                $this
->path './public/img/' $folder;
                
$imgs = array();
                
$count 0;
                foreach (
$_FILES as $key => $value{
                    $img_name 
$this->char_replace($value['name'][$count]'_');
                    
$count++;
                    
$config = array(
                    
'allowed_types' => 'jpg|jpeg|png|gif',
                    
'upload_path' => $this->path,
                    
'file_name' => $img_name
                
);
                    
$this->CI->load->library('upload'$config);
                  if(
$key != 'logo') :
                      if (!
$this->CI->upload->do_upload($key)) {
                    } 
else {
                        $q 
$this->CI->upload->data();
                        
$config['image_library''gd2';
                        
$config['source_image'$this->path '/' $q['file_name'];
                        
$config['new_image'$this->path '/thumbs';
                        
$config['create_thumb'FALSE;
                        
$config['maintain_ratio'TRUE;
                        
$config['width'128;
                        
$config['height'128;
        
                        
$this->CI->load->library('image_lib');
                        
$this->CI->image_lib->clear();
                        
$this->CI->image_lib->initialize($config);
                        
$this->CI->image_lib->resize();
                        
array_push($imgs$q['file_name']);
                    
}
                  
endif;
                

And this one is for replacing characters:

function char_replace($text$rep_simbol " ")
        
{
            $char 
= array('!''&''?''/''/\/'':'';''#''<''>''=''^''@''~''`''['']''{''}');
            return 
$name str_replace($char$rep_simbol$text);
        

Uploading is working great, but character replacement no quite. It is using only first letter from the name of file that is uploading, and rest is cut off. Also it is using same name for all images (name of the first image upload). What is wrong here?

 
Posted: 10 November 2012 05:56 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2009-04-15
453 posts

sounds like a typical case of trying to echo a string that is really an array for some reason

put a few var_dump’s in your code & see where the string stops working. let us know what debugging you’ve done & results and we’ll try to advise

 Signature 

Code By Jeff

Mahana Messaging Library

Problem with your query? Did you run

$this->db->last_query(); 

before you came to the forums for help?

 
Posted: 11 November 2012 10:38 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2012-01-09
117 posts

Change this:

$img_name $this->char_replace($value['name'][$count]'_'); 

To this:

$img_name $this->char_replace($value['name']'_');