• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] Best method question

#1
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);
                    

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#2
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)) {
 
   ...
 
 }

Reply

#3
(02-26-2016, 05: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.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.