Probleme Page de Gestion de fichier .ini
Utilisateur anonyme
-
Utilisateur anonyme -
Utilisateur anonyme -
Bonjour tous le Monde !! Bien passée les vacances ?! =P
Voici mon problème :
J'ai suivi ce tuto pour réaliser un système de gestion pour "php.ini" mais je n'arrive pas à trouver dans quelle variable initialiser le chemin de celui-ci. (C:\Program Files\EasyPHP-12.1\apache\php.ini)
Voici mes pages de code :
* class.php
* formulaire.php
Merci d'avance !! ^^
Voici mon problème :
J'ai suivi ce tuto pour réaliser un système de gestion pour "php.ini" mais je n'arrive pas à trouver dans quelle variable initialiser le chemin de celui-ci. (C:\Program Files\EasyPHP-12.1\apache\php.ini)
Voici mes pages de code :
* class.php
<?php class ini { var $fichier=""; var $groupe=""; var $item=""; var $valeur=""; var $fichier_ini=array(); function m_fichier($arg) { $this->fichier=$arg; $this->fichier_ini=null; $this->fichier_ini=array(); if(false!==($array=@parse_ini_file($arg, TRUE))) { $this->fichier_ini=$array; } else if(file_exists($arg) && $fichier_lecture=file($arg)) { foreach($fichier_lecture as $ligne) { $ligne_propre=trim($ligne); if(preg_match("#^\[(.+)\]$#",$ligne_propre,$matches)) { $groupe_curseur=$matches[1]; } else { if($ligne_propre[0]!=';' && $tableau=explode("=",$ligne,2)) { $this->fichier_ini[$groupe_curseur][$tableau[0]]=rtrim($tableau[1],"\n\r"); } } } } $this->valeur=$this->fichier_ini[$this->groupe][$this->item]; } function m_groupe($arg) { $this->groupe=$arg; $this->valeur=$this->fichier_ini[$this->groupe][$this->item]; return true; } function m_item($arg) { $this->item=$arg; $this->valeur=$this->fichier_ini[$this->groupe][$this->item]; return true; } function m_put($arg, $arg_i=false, $arg_g=false, $arg_f=false) { if($arg_f!==false) $this->m_fichier($arg_f); if($arg_g!==false) $this->m_groupe($arg_g); if($arg_i!==false) $this->m_item($arg_i); $this->fichier_ini[$this->groupe][$this->item]=$arg; $this->valeur=$arg; return $this->fichier." ==> [".$this->groupe."] ".$this->item."=".$this->valeur; } function m_count($arg_gr=false) { if($arg_gr===false) return array(1=>$gr_cou=count($this->fichier_ini), 0=>$itgr_cou=count($this->fichier_ini, COUNT_RECURSIVE), 2=>$itgr_cou-$gr_cou); else return count($this->fichier_ini[$arg_gr]); } function array_groupe($arg_gr=false) { if($arg_gr===false) $arg_gr=$this->groupe; return $this->fichier_ini[$arg_gr]; } function save() { $fichier_save=""; foreach($this->fichier_ini as $key => $groupe_n) { $fichier_save.=" [".$key."]"; foreach($groupe_n as $key => $item_n) { $fichier_save.=" ".$key."=".$item_n; } } $fichier_save=substr($fichier_save, 1); if(file_exists($this->fichier) && reset(explode('.',phpversion()))>=5) { if(false===file_put_contents($this->fichier, $fichier_save)) { die("Impossible d'écrire dans ce fichier (mais le fichier existe)."); } } else { $fichier_ouv=fopen($this->fichier,"w+"); if(false===fwrite($fichier_ouv, $fichier_save)) { die("Impossible d'écrire dans ce fichier (Le fichier n'existe pas)."); } fclose($fichier_ouv); } return true; } function clear() { $this->fichier=""; $this->groupe=""; $this->item=""; $this->valeur=""; $this->fichier_ini=null; $this->fichier_ini=array(); } function s_fichier() { $return=$this->fichier; if(file_exists($this->fichier)) unlink($this->fichier); $this->fichier=""; $this->valeur=""; return "fichier(".$return.") supprimé."; } function s_groupe() { $return=$this->groupe; if(isset($this->fichier_ini[$this->groupe])) unset($this->fichier_ini[$this->groupe]); $this->groupe=""; $this->valeur=""; return "groupe(".$return.") supprimé."; } function s_item() { $return=$this->item; if(isset($this->fichier_ini[$this->groupe][$this->item])) unset($this->fichier_ini[$this->groupe][$this->item]); $this->item=""; $this->valeur=""; return "item(".$return.") supprimé."; } function print_curseur() { echo "Fichier : <b>".$this->fichier."</b><br />"; echo "Groupe : <b>".$this->groupe."</b><br />"; echo "Item : <b>".$this->item."</b><br />"; echo "Valeur : <b>".$this->valeur."</b><br />"; return true; } function print_dossier() { if(is_dir($this->fichier)) { echo "<img src='dir.png' alt='Dossier' /><span style='position:relative; top:-10px;font-size:20px; font-weight:bold;'>".$this->fichier."</span><br />"; if($handle=opendir($this->fichier)) { while(false!==($file=readdir($handle))) { if(substr($file, -4, 4)==".ini") { echo " <a href='?fichier=".$file."'><img src='iniicone.png' alt='Ini' style='border:none;' /></a> ".$file."<br />"; } } closedir($handle); } return true; } else { echo "L'élément sélectionné n'est pas un dossier"; return false; } } function print_fichier() { if(file_exists($this->fichier) && is_file($this->fichier) && $fichier_lecture=file($this->fichier)) { foreach($fichier_lecture as $ligne) { $ligne=preg_replace("#\s$#","",$ligne); if(preg_match("#^\[.+\]\s?$#",$ligne)) $groupe=false; if(preg_match("#^\[".preg_quote($this->groupe, "#")."\]$#",$ligne)) { $echo.= "<span style='background-color:aqua;'>".htmlspecialchars($ligne)."</span><br />"; $groupe=true; } elseif($groupe==true && $this->item==reset(explode("=",$ligne))) $echo.= "<span style='background-color:yellow;'>".htmlspecialchars($ligne)."</span><br />"; else $echo.= htmlspecialchars($ligne)."<br />"; } echo $echo; } else { echo "Le fichier n'existe pas ou est incompatible"; } $this->valeur=$this->fichier_ini[$this->groupe][$this->item]; return true; } function m_valeur($arg_item, $arg_groupe) { return $this->fichier_ini[$arg_groupe][$arg_item]; } } ?>
* formulaire.php
<?php // Ou avec include include('./include/class.php'); session_start(); if(isset($_SESSION['ini'])) $ini_objet=unserialize($_SESSION['ini']); else $ini_objet=new ini(); if(isset($_GET['fichier'])) { $dossier=$ini_objet->fichier; $dossier=preg_replace('#/$#','',$dossier).'/'; $ini_objet->m_fichier($dossier.$_GET['fichier']); header('Location:./ini.php5'); } if(isset($_POST['clear'])) { $ini_objet->clear(); } if(isset($_POST['fichier'])) { if($_POST['fichier']=='Changer') { $ini_objet->m_fichier(stripslashes($_POST['source'])); } elseif($_POST['fichier']=='Supprimer') { $ini_objet->s_fichier(); } } if(isset($_POST['groupe'])) { if($_POST['groupe']=='Changer') { $ini_objet->m_groupe(stripslashes($_POST['source'])); } elseif($_POST['groupe']=='Supprimer') { $ini_objet->s_groupe(); $ini_objet->save(); } } if(isset($_POST['item'])) { if($_POST['item']=='Changer') { $ini_objet->m_item(stripslashes($_POST['source'])); } elseif($_POST['item']=='Supprimer') { $ini_objet->s_item(); $ini_objet->save(); } } if(isset($_POST['valeur'])) { if($_POST['valeur']=='Changer') { $ini_objet->m_put(stripslashes($_POST['source'])); $ini_objet->save(); } elseif($_POST['valeur']=='Supprimer') { $ini_objet->m_put(''); $ini_objet->save(); } } $_SESSION['ini']=serialize($ini_objet); /* La ligne précédente et les 5 plus haut permettent de sauvegarder les opérations réalisées dans une variable de session et donc, de pouvoir circuler dans un .ini en plusieurs chargements de page. */ ?> <html> <head> <title>Traitement INI</title> <style> form { margin:0px; padding:0px; } fieldset { margin-right:10px; margin-bottom:8px; border:1px black solid; } legend { color:#333333; font-style:italic; font-weight:bolder; font-size:18px; } </style> </head> <body> <div style="float:right;"> <div style="width:400px; padding:6px; margin-right:12px; border:1px solid black;"> <div style="float:right; text-align:right;"> <?php $stat=$ini_objet->m_count(); echo '<strong>'.$stat[1].'éléments</strong> dans ce fichier<br /> dont <strong>'.$stat[0].'groupes</strong> et <strong>'.$stat[2].' items</strong>.<br /> <strong>'.$ini_objet->m_count($ini_objet->groupe).' items</strong> dans ce groupe.'; ?> </div> <u><i><b>Information sur le curseur</b></i></u><br /> <?php $ini_objet->print_curseur(); ?> </div> <div style="width:400px; height:400px; overflow:auto; padding:6px; margin-top:12px; margin-right:12px; border:1px solid black;"> <u><i><b>Aperçu du <?php if(is_dir($ini_objet->fichier)) echo 'dossier'; else echo 'fichier'; ?></b></i></u><br /><br /> <span style="font-family:courier; white-space:nowrap;"><?php if(is_dir($ini_objet->fichier)) $ini_objet->print_dossier(); else $ini_objet->print_fichier(); ?></span> </div> </div> <fieldset><legend>Fichier</legend> <form method="post" action=""> <label>Fichier : <input type="text" name="source" /></label><br /> <input type="submit" name="fichier" value="Changer" /> </form> <form method="post" action=""> <input type="submit" name="fichier" value="Supprimer" /> </form> </fieldset> <fieldset><legend>Groupe</legend> <form method="post" action=""> <label>Groupe : <input type="text" name="source" /></label><br /> <input type="submit" name="groupe" value="Changer" /> </form> <form method="post" action=""> <input type="submit" name="groupe" value="Supprimer" /> </form> </fieldset> <fieldset><legend>Item</legend> <form method="post" action=""> <label>Item : <input type="text" name="source" /></label><br /> <input type="submit" name="item" value="Changer" /> </form> <form method="post" action=""> <input type="submit" name="item" value="Supprimer" /> </form> </fieldset> <fieldset><legend>Valeur</legend> <form method="post" action=""> <label>Valeur : <input type="text" name="source" /></label><br /> <input type="submit" name="valeur" value="Changer" /> </form> <form method="post" action=""> <input type="submit" name="valeur" value="Supprimer" /> </form> </fieldset> <br /> <fieldset><legend>Réinitialiser</legend> <form method="post" action=""> <input type="submit" name="clear" value="Effacer" /> </form> </fieldset> </body> </html>
Merci d'avance !! ^^
A voir également:
- Probleme Page de Gestion de fichier .ini
- Fichier bin - Guide
- Fichier epub - Guide
- Impossible de supprimer une page word - Guide
- Fichier rar - Guide
- Comment réduire la taille d'un fichier - Guide