Welcome Guest, Not a member yet? Register   Sign In
using php glob() problem
#11

[eluser]CroNiX[/eluser]
Yes, FCPATH is a file system path, not a URI. Get your base_url() fixed and use that.

What is the directory structure of your project? You don't seem to have things set up properly, so this is trivial until you get that fixed.

What is the exact path to your index.php file?
C:/Program Files (x86)/wamp/www/clipart/?
#12

[eluser]brian88[/eluser]
yes ur right, FCPATH returns
C:\Program Files (x86)\wamp\www\clipart\

Code:
public function index() {
  // logic
  $folder = base_url() . "assets/images/clipart/mascots/";
  echo base_url(); // http://localhost/clipart/
  echo $folder; // http://localhost/clipart/assets/images/clipart/mascots/
  echo FCPATH; // C:\Program Files (x86)\wamp\www\clipart\

  $images = glob($folder."*.gif");
  print_r( $images ); // returns empty array :(

  // views
  $this->load->view('header_view', $data);
  $this->load->view('main_view', $data);
  $this->load->view('footer_view');
} // end function

I didn't think my base_url is broken. But glob() always returns an empty array when i clearly have .gifs in that folder
#13

[eluser]pbflash[/eluser]
I think glob needs the path to the files not the URI so using base_url is not going to work.
#14

[eluser]CroNiX[/eluser]
I know, but he needs to use base_url() for creating the src to the images or all of the urls will look like "C:\\Program Files (x86)\\wamp\\www\\clipart\\assets/images/clipart/mascots/badger.gif".

Personally I'd use scandir() instead of glob(), which will only retrieve the files and not the paths. Then use base_url() to create the img src's.
#15

[eluser]brian88[/eluser]
Thanks a lot cronix. I didn't know there was a scandir().

Heres my final code, hopefully it works when I throw it online too.

Code:
$folder = FCPATH . "assets/images/clipart/mascots/";
  echo $folder; // C:\Program Files (x86)\wamp\www\clipart\assets/images/clipart/mascots/

// get rid of those pesky dots it returns by default.
  $data['images'] = array_diff(scandir($folder), array('..', '.'));

  print_r( $data['images'] );
// returns Array ( [2] => badger.gif [3] => bear.gif [4] => bee.gif )

I know how to list the folders(categories) now. Can u then list the images that are under that folder(categories)?




Theme © iAndrew 2016 - Forum software by © MyBB