• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is_dir and Is_file inside foreach loop error.

#1
I am getting error in my foreach loop using

Array to string conversion error. On the line where is_dir and is_file.

Question: Where have I gone wrong? How to fix it?

Seems to be if any files in sub folder throws the error that's what causing error.


PHP Code:
foreach ($files as $image) {

if (
is_dir($directory $image)) {

$data['images'][] = array(
'name' => $image
);

} elseif (
is_file($directory $image)) {
$data['images'][] = array(
'name' => $image
);




Controller function


PHP Code:
public function index() {
$userdata $this->user_model->getuser($this->user_model->getuserid());

if (
$this->input->get('directory')) {
$directory FCPATH 'uploads/' $userdata['upload_folder'] .'/'$this->input->get('directory') .'/';
} else {
$directory FCPATH 'uploads/' $userdata['upload_folder'] .'/';
}

$files = array();

$files directory_map($directoryFALSETRUE);

   $data['images'] = array();

foreach (
$files as $image) {

if (
is_dir($directory $image)) {

$data['images'][] = array(
'name' => $image
);

} elseif (
is_file($directory $image)) {
$data['images'][] = array(
'name' => $image
);

}

$this->load->view('extension/filemanager'$data);


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

#2
Perhaps your directory map is returning an array that is more complex than you have allowed for, so your $image is not a filename but an array of filenames. If you output the files array you generated with a var_dump what do you get?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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