www.webdeveloper.com
Results 1 to 4 of 4

Thread: Strange include problem within a funciton

  1. #1
    Join Date
    Nov 2006
    Posts
    9

    Strange include problem within a funciton

    PHP Code:
        if(file_exists($dir))
        {
        
    $dh  opendir($dir);
            while (
    $filename readdir($dh)) 
            {
        
                if(
    $filename != "." && $filename != "..")
                {
                    
    $files[] = $dir "/" $filename;
                    
    $reached++;
                }
            
            }
            if(
    $files[0]!=null)
            {
                    while(
    $now $reached)
                    {                    
                        
    //include content
                        
    $post$files[$now];
                        include(
    $post);//<THIS IS THE PROBLEM! 
    The above code is supposed to go through a directory and include all the files inside. The problem is that it says its cant include the first file, which is aparrently an empty string.

    Warning: listposts() [function.include]: Failed opening '' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php')

    but when i echo the contents of $post, it is a working path for the second file.

    whats going on? theres only one file in there!

    thanks for any help guys!
    Last edited by Gigaman2003; 11-09-2006 at 06:36 PM.

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    are you sure $files[$now] has a value?

    PHP Code:
    $post$files[$now];
    echo 
    'got: '.$post.' as post';
                        include(
    $post);//<THIS IS THE PROBLEM! 
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,384
    How about a little debug code before the include statement:
    PHP Code:
    // include content
    $post$files[$now];
    if(
    file_exists($post))
    {
      if(
    is_readable($post))
      {
        include(
    $post);
      }
      else
      {
        
    user_error("File '$post' is not readable"E_USER_WARNING);
      }
    else
    {
      
    user_warning("File '$post' does not exist"E_USER_WARNING);

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Nov 2006
    Posts
    9
    Quote Originally Posted by chazzy
    are you sure $files[$now] has a value?

    PHP Code:
    $post$files[$now];
    echo 
    'got: '.$post.' as post';
                        include(
    $post);//<THIS IS THE PROBLEM! 
    yes it does, if not when i echoed it nothing would have appeared

    with debug code

    File '' does not exist

    same problem :/

    ohdear i seem to have found the problem

    for some reason i unset $now before the while loop started!

    no wonder it took one loop to add one to $now and make it 0;
    Last edited by Gigaman2003; 11-09-2006 at 06:58 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles