CodeIgniter Forums
[Solved] Best method question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: [Solved] Best method question (/showthread.php?tid=64502)



[Solved] Best method question - wolfgang1983 - 02-26-2016

My foreach loop picks up files and folders. But I am still having issue because when original_image is a folder it throws error.


Code:
A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: controllers/Filemanager.php

Line Number: 204

Backtrace:

File: C:\wamp\www\project-2-upload\application\controllers\Filemanager.php
Line: 204
Function: _error_handler

File: C:\wamp\www\project-2-upload\application\controllers\Filemanager.php
Line: 91
Function: resize

File: C:\wamp\www\project-2-upload\index.php
Line: 292


I am not sure the best method of where to use if is file or a if is dir?

Because I use a input get as well.

Any suggestions?


PHP Code:
$this->load->helper('directory');

$get_directory $this->input->get('directory');

if (isset(
$get_directory)) {
    
$cached_images directory_map('./images/cache/' $get_directory);
} else {
    
$cached_images directory_map('./images/cache/catalog/');
}

foreach (
$cached_images as $position => $image) { 

    
$original_image str_replace('_thumb-' $width 'x' $height''$image);

    
$path '';

    if (isset(
$get_directory)) {
        
$path '/' $get_directory '/' $original_image;
    } else {
        
$path '/catalog/' $original_image// Line 204
    
}

    
var_dump(FCPATH 'images'$path);
                    




RE: Best method question - Diederik - 02-26-2016

The directory_map() function gives you back a nested array. If you loop through it you should perform an extra verification to check if the value is a string (containing your image file name) or an array (containing all the files in the sub directory).

PHP Code:
foreach ($cached_images as $position => $image) { 
 
 if (is_string($image)) {
 
   ...
 
 }




RE: Best method question - wolfgang1983 - 02-26-2016

(02-26-2016, 04:46 PM)Diederik Wrote: The directory_map() function gives you back a nested array. If you loop through it you should perform an extra verification to check if the value is a string (containing your image file name) or an array (containing all the files in the sub directory).

PHP Code:
foreach ($cached_images as $position => $image) { 
 
 if (is_string($image)) {
 
   ...
 
 }


thanks for that I will read more on is_string that is a new one for me.