<?php $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : "" ;//echo"action=$action~~<br>"; $dossier = (isset($_REQUEST['dossier'])) ? $_REQUEST['dossier'] : "" ;//echo"action=$action~~<br>"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <!-- Date de création: 30/01/2012 --> <head> <title></title> </head> <body background="body_bg.jpg"> <?php set_time_limit(0); switch ($action) { case 'php4php5': ?> <table width="800" height="100%" border="1" align="center"> <tr> <td><?php filePhp($dossier);?></td> </tr> </table> <center> <h3>Passage de Php4 à Php5</h3> <h4><u>Probleme des "short tags"</u><br><br> ˂?...?> & ˂?=...?><br> deviennent<br> ˂?php...?> & ˂?php echo ...; ?></h4> <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"> <input type="text" name="dossier" size="40" maxlength="256" value="Adresse du dossier à traiter"> <input type="hidden" name="action" value="php4php5"> <input type="submit" value="envoi" /> </form> </center> <?php break; default: ?> <center> <h3>Passage de Php4 à Php5</h3> <h4><u>Probleme des "short tags"</u><br><br> ˂?...?> & ˂?=...?><br> deviennent<br> ˂?php...?> & ˂?php echo ...; ?></h4> <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"> <input type="text" name="dossier" size="40" maxlength="256" value="Adresse du dossier à traiter"> <input type="hidden" name="action" value="php4php5"> <input type="submit" value="envoi" /> </form> </center> <?php break; } function filePhp($dir){ $dh = opendir ($dir); while (($file = readdir ($dh)) !== false ){ if ($file !== '.' && $file !== '..'){ if (is_dir ($dir.'/'.$file)){ $s_dir = ($dir.'/'.$file); filePhp($s_dir); // si on trouve un repertoire, on fait un appel recursif pour fouiller ce repertoire } else { if (file_exists ($dir.'/'.$file)){ $fileName = $dir.'/'.$file; $pos = strlen($fileName); $suf = substr($fileName,$pos-3); if($suf != 'jpg' && $suf != 'png' && $suf != 'gif'&& $suf != 'psd'&& $suf != 'pdf'&& $suf != 'css'&& $suf != 'ico'&& $suf != 'tml'&& $suf != 'sql'&& $suf != 'ini'&& $suf != 'zip') traite($fileName); // si on trouve un fichier php, on le traite } } } } closedir ($dh); } function traite($file){ $pos = strlen($file); $suf = substr($file,$pos-3); $contenu = ''; $fd = fopen($file, "r"); while (!feof($fd)){ $contenu .= fgets($fd);//nettoyage devant derriere } fclose($fd); $contenu0 = $contenu; $p = 1; while ($p !=''){ $p = strpos($contenu, '<?=' ); //echo"p=$p<br>"; if($p !=''){ $str1 = substr($contenu,0,$p+3);//echo "str1 = $str1<br>"; $str1 = str_replace('<?=', 'xxphpxechox', $str1); //echo "str1 = $str1<br>"; $str2 = substr($contenu,$p+3); $q = strpos($str2,'?>'); $str2 = substr_replace($str2, '; ', $q ,0); //echo "str2 = $str2<br>"; $contenu = $str1.$str2; //echo" $contenu<br><br><br><br>"; } } $contenu = str_replace('<?', '<?php ', $contenu); $contenu = str_replace('<?php php', '<?php ', $contenu); $contenu = str_replace('xxphpxechox', '<?php echo ', $contenu); if($contenu != $contenu0)echo"$file<br>"; unlink($file); $fp = fopen($file, 'a '); fputs($fp, $contenu); fputs($fp,"\n"); fclose($fp); } ?> </body> </html>
Passage de Php4 à Php5
Probleme des "short tags"
˂?...?> & ˂?=...?>
deviennent
˂?php...?> & ˂?php echo ...; ?>