Jump to content

newbie... Opendir help!!


kurtfloyd

Recommended Posts

Hello,

 

I confess i don't know much in PHP but i need to use it in a web based quiz program that

uses it and i have a problem.

 

 

I can't open a directory and i don't know what's the problem.

 

 

Here is the info...

 

 

The php scripts are located in this directory

 

 

quizscience.xxx.com/gestionnaire

 

 

and i have a XML subdirectory within this last directory.

 

 

When i lauch this script it doesn't work, why?

 

 

The folder value is :  $sXMLFileFolder = "./XML/";

 

 

 

}

 

 

    // Open the XML Source file directory

    $oDir = opendir($sXMLFileFolder);

    if ($oDir) {

        while (($sFile = readdir($oDir)) !== false) {

            $sFilePath = $sXMLFileFolder . $sFile;

            if(is_file($sFilePath)){

                $xml = @simplexml_load_file($sFilePath);

                if(!$xml){

                    //Add file in the error list

                    $aFileNameErrors[count($aFileNameErrors)] = $sFile;

                }else{

                    $sQuizIdent = $xml->quiz->quizident;

                    $sQuizVersion = $xml->quiz->quizversion;

 

                    if(isInArray($sQuizIdent ."-" . $sQuizVersion,$aExistingQuizs)){

                        //Add file in the existing list

                        $aFileNameExists[count($aFileNameExists)] = $sFile;

                    }else{

                        //Add file in the new list

                        $aFileNameNews[count($aFileNameNews)] = $sFile;

                    }

                }

            }

        }

        closedir($oDir);

    }

 

 

Please i need some help before i get all my hair off !!! ;-)

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/44172-newbie-opendir-help/
Share on other sites

Here is the script.

 

/* The $sXMLFileFolder value is in the settings.inc.php script. */

<?php
    include_once("langr.inc.php");
    include_once("settings.inc.php");
    include_once("functions.inc.php");
    include("isauth.php");
    
    //Variables
    $aExistingQuizs = array();
    $aFileNameExists = array();
    $aFileNameNews = array();
    $aFileNameErrors = array();
    
    $sNewStatut = "-";
    $sExistsStatut = $sLR["aq_exi_lbl"];
    $sErrorStatut = $sLR["aq_if_lbl"];
    
    //Connection
    $oServerConn = mysql_connect($sMySQLLocation,$sMySQLUser,$sMySQLPassword);
    if(!$oServerConn){
        die(mysql_error());
    }
    
    mysql_select_db($sMySQLDatabase);
    
    //Get existing quizs
    $sQuery = "select * from nq_quizs";
    
    $oRS = executeQuery($sQuery);
    
    for($i = 0;$i < mysql_num_rows($oRS);$i++){
        $aExistingQuizs[$i] = mysql_result($oRS,$i,"QuizIdent") . "-" . mysql_result($oRS,$i,"QuizVersion");
    }
    
    // Open the XML Source file directory
    $oDir = opendir($sXMLFileFolder);
    if ($oDir) {
while (($sFile = readdir($oDir)) !== false) {
     $sFilePath = $sXMLFileFolder . $sFile;
     if(is_file($sFilePath)){
	$xml = @simplexml_load_file($sFilePath);
	 if(!$xml){
	    //Add file in the error list
	    $aFileNameErrors[count($aFileNameErrors)] = $sFile;
	 }else{
	    $sQuizIdent = $xml->quiz->quizident;
	    $sQuizVersion = $xml->quiz->quizversion;
	    
	    if(isInArray($sQuizIdent ."-" . $sQuizVersion,$aExistingQuizs)){
		//Add file in the existing list
		$aFileNameExists[count($aFileNameExists)] = $sFile;
	    }else{
		//Add file in the new list
		$aFileNameNews[count($aFileNameNews)] = $sFile;
	    }
	 }
    }
}
closedir($oDir);
    }
    
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
            <link rel="stylesheet" type="text/css" href="includes/main.css" />
            <title><?php echo $sLR["title"]; ?></title>
</head>
<body style="margin:0px;">
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td align="center" style="background:url(images/bandetitre_pat.jpg) repeat-x;" height="56">
				<img src="images/bandetitre.jpg" />
			</td>
		</tr>
		<tr>
			<td width="100%" height="100">
				 
			</td>
		</tr>
		<tr>
			<td align="center">
                                    <table width="745" cellpadding="0" cellspacing="0" border="0">
                                        <tr>
                                            <td width="100%" height="30">
                                                <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                                    <tr>
                                                        <td height="30" width="50%" valign="middle" align="left"><font class="section_header"><?php echo $sLR["aq_titre"]; ?></font></td>
                                                        <td height="30" width="50%" valign="middle" align="right"><a class="small" href="quizlist.php"><?php echo $sLR["menu_bql_link"]; ?></a></td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="100%" height="5" valign="middle"><img src="images/ligne.gif" width="100%" height="1" alt="" border="0" /></td>
                                        </tr>
                                        <tr>
                                            <td width="100%" height="30" valign="middle" align="right">
                                                 
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="100%" height="20"><img src="images/spacer.gif" width="100%" height="50"></td>
                                        </tr>
                                        <tr>
                                            <td width="100%" height="30" align="left" valign="middle"><font class="list_header"><?php echo $sLR["aq_lhead_lbl"]; ?></font></td>
                                        </tr>
                                        <tr>
                                            <td width="100%" height="20" valign="middle"><img src="images/ligne.gif" width="100%" height="1" /></td>
                                        </tr>
                                        <tr>
                                            <td width="100%">
                                                <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                                    <tr>
                                                        <td width="425" height="25" align="left"><font class="list_header"><?php echo $sLR["aq_nc_lbl"]; ?></font></td>
                                                        <td width="15" height="25" align="left"><img src="images/spacer.gif" width="100%" height="25"></td>
                                                        <td width="120" height="25" align="center"><font class="list_header"><?php echo $sLR["aq_sc_lbl"]; ?></font></td>
                                                        <td width="85" height="25" align="center"><font class="list_header"><?php echo $sLR["aq_ac_lbl"]; ?></font></td>
                                                    </tr>
                                                    <tr>
                                                        <td width="100%" height="10" colspan="5"><img src="images/spacer.gif" width="100%" height="10"></td>
                                                    </tr>
                                                    <?php
                                                        for($i = 0;$i < count($aFileNameNews);$i++){
                                                            writeRow($aFileNameNews[$i],$sNewStatut,true);
                                                        }
                                                        for($i = 0;$i < count($aFileNameExists);$i++){
                                                            writeRow($aFileNameExists[$i],$sExistsStatut,false);
                                                        }
                                                        for($i = 0;$i < count($aFileNameErrors);$i++){
                                                            writeRow($aFileNameErrors[$i],$sErrorStatut,false);
                                                        }
                                                    ?>
                                                </table>
                                            </td>
                                    </table>
                                </td>
		</tr>
	</table>
</body>
</html>
<?php
    function writeRow($sFileName,$sStatut,$bShowAction){
        global $sLR;
        
        echo "<tr>";
        echo "  <td width=\"425\" height=\"25\" class=\"listContent\" align=\"left\">" . htmlentities($sFileName) . "</td>";
        echo "  <td width=\"15\" height=\"25\"><img src=\"images/spacer.gif\" width=\"100%\" height=\"2\" /></td>";
        echo "  <td width=\"120\" height=\"25\" class=\"listContent\" align=\"center\">$sStatut</td>";
        echo "  <td width=\"85\" height=\"25\" align=\"center\">";
        if($bShowAction){
            echo "    <a href=\"addquiz.php?fn=$sFileName\">" . $sLR["aq_add_link"] . "</a>";
        }else{
            echo "     ";
        }
        echo "  </td>";
        echo "</tr>";
    }

    mysql_close();
?>

 

EDITED BY WILDTEEN88: Please use the code tags (


) when posting code in the forum. Thank you.

Link to comment
https://forums.phpfreaks.com/topic/44172-newbie-opendir-help/#findComment-214485
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.