www.webdeveloper.com
Results 1 to 2 of 2

Thread: Error in function structure, blank page result ?

  1. #1
    Join Date
    Feb 2006
    Posts
    352

    Post Error in function structure, blank page result ?

    Good day to you all,
    here I'm trying to add to a listing directory code, another piece of code that send the list result to an html page.

    It's seems like the "sending to the other page code never get executed ?

    I always have this function proble can somebody so me my mistake !


    Here is my code :

    PHP Code:



    <?php

    error_reporting
    (E_ALL);
    ini_set("display_errors""on");

             
    set_time_limit(0);
            
    $directory "Art/";


    function 
    dirList ($directory)
    {
     
        
    //create 2 arrays - one for folders and one for files
       
    $folders = array();
       
    $files = array();
     
        
    // create a handler for the directory
        
    $handler opendir($directory);
     
        
    // keep going until all files in directory have been read
    while (false !== ($file readdir($handler))) {  
     
            
    // if $file isn't this directory or its parent,
            // add it to the results array
            
    if ($file != '.' && $file != '..')
           
            
    // If file is directory, mark it in bold.

           
    if(is_dir($directory.$file)) {
            
    array_push($folders,$file);
            
                if (
    time() - filemtime($directory.$file) < 604800) {
        
    $folder_modified[] = "<span style=\"color:#DB1212;\"><li><div class=\"folder\"><img src=\"plus_icon.gif\"  onclick=\"Toggle('".preg_replace('/\//','_',$directory."".$file)."'); return false;\" /><b>".$file."</b></div>";
    } elseif (
    time() - filemtime($directory.$file) < 31556926) {
        
    $folder_modified[] = "<span style=\"color:#003366;\"><li><div class=\"folder\"><img src=\"plus_icon.gif\"  onclick=\"Toggle('".preg_replace('/\//','_',$directory."".$file)."'); return false;\" /><b>".$file."</b></div>";
    } else {
    $folder_modified[] = "<span style=\"color:#000000;\"><li><div class=\"folder\"><img src=\"plus_icon.gif\"  onclick=\"Toggle('".preg_replace('/\//','_',$directory."".$file)."'); return false;\" /><b>".$file."</b></div>";}
     
            
           
            
    // Else not styled
            
    }else{
            
    array_push($files,$file);
         
    $filenamecor substr($file0, -4);
        if (
    time() - filemtime($directory.$file) < 604800) {
        
    $file_modified[] = '<span style="color:#DB1212;">'.$filenamecor.'<span>';
    } elseif (
    time() - filemtime($directory.$file) < 31556926) {
        
    $file_modified[] = '<span style="color:#003366;">'.$filenamecor.'<span>';
    } else {
    $file_modified[] = '<span style="color:#000000;">'.$filenamecor.'<span>';}
     
     
        }
        }

    $output "";

        
    $output .= "<ul id=\"".preg_replace('/\//','_',substr($directory,0,strlen($directory)-1))."\">\n"//start a new unordered list for every iteration through dirList
     
    $dircor $directory;
        
    // tidy up: close the handler
        
    closedir($handler);
        foreach(
    $folders as $folder=>$file) {
            
          
    $output .= "<li><div class=\"folder\">".$folder_modified[$folder]."</div>"//echo the folder name enclosed in a list item
            
    dirList($directory.$file.'/'); //loop through the contents of $folder
          
    $output .= "</li>\n"//close this list item after all files and folders in $folder have been looped through
       
       
        
    }
     
        foreach(
    $files as $key=>$file) {

          
    $output .= "<li><a href=\"index.html\" onclick=\"load('image_view.php?dir=".$dircor."&file=".$file."','boxdisp');return false;\">&nbsp;".$file_modified[$key]."</a></li>\n"//echo the file name enclosed in a list item
        
    }
     
     
        
    $output .= "</ul>\n"//close the unordered list

          
    return $output;

    $filename 'menu.html';
    // Let's make sure the file exists and is writable first.
    if (is_writable($filename)) {

        
    // In our example we're opening $filename in append mode.
        // The file pointer is at the bottom of the file hence
        // that's where $somecontent will go when we fwrite() it.
        
    if (!$handle fopen($filename'a')) {
             echo 
    "Cannot open file ($filename)";
             exit;
        }

        
    // Write $somecontent to our opened file.
        
    if (fwrite($handle,$output) === FALSE) {
            echo 
    "Cannot write to file ($filename)";
            exit;
        }

        echo 
    "Success, wrote () to file (".$filename.")";

        
    fclose($handle);

    } else {
        echo 
    "The file ".$filename." is not writable";
    }

    }
        

    dirList ($directory);
        




    ?>
    the result of this is a blank page.


    Thanks !
    That's why we are not alone on earth, to help each other !
    Let's REbuild that for ourselves !

  2. #2
    Join Date
    Aug 2006
    Location
    Michigan
    Posts
    1,046
    Hmm I have made a couple of changes and commets, look for // <-- Comment

    PHP Code:
    <?php

    error_reporting
    (E_ALL);
    ini_set("display_errors""on");

    set_time_limit(0);
        
    $directory "Art/";


    function 
    dirList($directory) {
        
    // Check if filename is writeable
        
    $filename 'menu.html';
        
        if(!
    isWriteable($filename)) {
            echo 
    "Please check file: " $filename " The was a problem";
            exit;
        }
        
        
    //create 2 arrays - one for folders and one for files
        
    $folders    = array();
        
    $files        = array();
        
        
    // create a handler for the directory
        
    $handler opendir($directory);
        
        
    // keep going until all files in directory have been read
        
    while (false != ($file == readdir($handler))) {  // <-- Changed this line

        // if $file isn't this directory or its parent,
        // add it to the results array
        
    if($file != '.' && $file != '..'// <-- Does these need brackets ?

            // If file is directory, mark it in bold.
            
    if(is_dir($directory.$file)) {
                
    array_push($folders,$file);

                if(
    time() - filemtime($directory.$file) < 604800) {
                    
    $folder_modified[] = "<span style=\"color:#DB1212;\"><li><div class=\"folder\"><img src=\"plus_icon.gif\"  onclick=\"Toggle('".preg_replace('/\//','_',$directory."".$file)."'); return false;\" /><b>".$file."</b></div>";
                } elseif (
    time() - filemtime($directory.$file) < 31556926) {
                    
    $folder_modified[] = "<span style=\"color:#003366;\"><li><div class=\"folder\"><img src=\"plus_icon.gif\"  onclick=\"Toggle('".preg_replace('/\//','_',$directory."".$file)."'); return false;\" /><b>".$file."</b></div>";
                } else {
                    
    $folder_modified[] = "<span style=\"color:#000000;\"><li><div class=\"folder\"><img src=\"plus_icon.gif\"  onclick=\"Toggle('".preg_replace('/\//','_',$directory."".$file)."'); return false;\" /><b>".$file."</b></div>";
                }
            
    // Else not styled
            
    } else {
                
    array_push($files,$file);
                
    $filenamecor substr($file0, -4);
                
                if(
    time() - filemtime($directory.$file) < 604800) {
                    
    $file_modified[] = '<span style="color:#DB1212;">'.$filenamecor.'<span>';
                } elseif (
    time() - filemtime($directory.$file) < 31556926) {
                    
    $file_modified[] = '<span style="color:#003366;">'.$filenamecor.'<span>';
                } else {
                    
    $file_modified[] = '<span style="color:#000000;">'.$filenamecor.'<span>';
                }
            }
        } 
    // <-- End of while

        
    $output "";

        
    //start a new unordered list for every iteration through dirList
        
    $output .= "<ul id=\"".preg_replace('/\//','_',substr($directory,0,strlen($directory)-1))."\">\n"

        
    $dircor $directory;
        
        
    // tidy up: close the handler
        
    closedir($handler);
        foreach(
    $folders as $folder=>$file) {
            
    //echo the folder name enclosed in a list item
            
    $output .= "<li><div class=\"folder\">".$folder_modified[$folder]."</div>"
            
            
    //loop through the contents of $folder
            
    dirList($directory.$file.'/'); 
            
            
    //close this list item after all files and folders in $folder have been looped through
            
    $output .= "</li>\n"
        }

        foreach(
    $files as $key=>$file) {
            
    //echo the file name enclosed in a list item
            
    $output .= "<li><a href=\"index.html\" onclick=\"load('image_view.php?dir=".$dircor."&file=".$file."','boxdisp');return false;\">&nbsp;".$file_modified[$key]."</a></li>\n"
        }

        
    //close the unordered list
        
    $output .= "</ul>\n"

        return 
    $output;
    }

    function 
    isWriteable($filename) {
        
    $return false;
        
        
    // Let's make sure the file exists and is writable first.
        
    if(is_writable($filename)) { 
            
    $return == true;
            
            
    // In our example we're opening $filename in append mode.
            // The file pointer is at the bottom of the file hence
            // that's where $somecontent will go when we fwrite() it.
            
    if(!$handle fopen($filename'a')) {
                echo 
    "Cannot open file ($filename)"
                
    $return == false;
            } 

            
    // Write $somecontent to our opened file.
            
    if(fwrite($handle,$output) === FALSE) { 
                echo 
    "Cannot write to file ($filename)"
                
    $return == false;
            }

            echo 
    "Success, wrote () to file (".$filename.")";

            
    fclose($handle);
        } else {
            echo 
    "The file ".$filename." is not writable";
        }
        
        return 
    $return;
    }

    dirList ($directory);

    ?>

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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.17139 seconds
  • Memory Usage 2,969KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (2)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • bbcode_parse_start
  • postbit_imicons
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates