Et qu'en est-il des très gros fichiers? je ne suis pas sûr que 300M passent d'un coup la dedans...
Toujours est-il que je n'ai pas le temps (en ce moment) pour apprendre ces choses là!
Mais merci à toi pour ta contribution
Pour un code qui devient par contre illisible je trouve :/
Et qu'en est-il des très gros fichiers? je ne suis pas sûr que 300M passent d'un coup la dedans...
Toujours est-il que je n'ai pas le temps (en ce moment) pour apprendre ces choses là!
Mais merci à toi pour ta contribution
<table summary="UTF8_izer" style="padding: 2px; border: 1px solid black;">
<tr>
<td><b>Fichier ou dossier traité</b></td>
<td><b>Traitement effectué</b></td>
<td><b>Etat</b></td>
</tr>
<?php
class html_entity_decode_filter extends php_user_filter
{
public function filter($in, $out, &$consumed, $closing)
{
while($bucket = stream_bucket_make_writeable($in))
{
$bucket->data = html_entity_decode($bucket->data, ENT_NOQUOTES, 'UTF-8');
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
}
function utf8izer($dest, $path, array $ext_filter = array(), array $dir_filter = array())
{
stream_filter_register('string.html_entity_decode', 'html_entity_decode_filter');
//$realpath = realpath('../phpmyadmin');
$dir = new RecursiveDirectoryIterator($path);
$iterator = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::SELF_FIRST);
foreach($iterator as $file)
{
echo '<tr><td>Traitement de '.$file->getRealPath().'</td>';
$filename = str_replace($path, '', $file->getRealPath());
//$dirname = pathinfo($filename, PATHINFO_DIRNAME);
if ($file->isDir()) {
echo '<td style="color: purple;">Répertoire, création du répertoire cible...</td>'."\n";
if (!mkdir($dest . $filename, 0777, true)) {
echo '<td style="color: red;">KO</td>'."\n";
} else {
echo '<td style="color: green;">OK</td>'."\n";
}
} else {
if ($file->isFile()) {
if (in_array(pathinfo($file->getFilename(), PATHINFO_EXTENSION), $ext_filter)) {
echo '<td style="color: green;">Extension traitée, conversion...</td>'."\n";
if (copy('php://filter/read=string.html_entity_decode|convert.iconv.cp1252%2FUTF-8/resource=' . $file->getRealPath(), $dest . $filename)) {
echo '<td style="color: green;">OK</td>'."\n";
} else {
echo '<td style="color: red;">KO</td>'."\n";
}
} else {
echo '<td style="color: blue;">Extension non traitée, recopie simple...</td>'."\n";
if (!copy($file->getRealPath(), $dest . $filename)) {
echo '<td style="color: red;">KO</td>'."\n";
} else {
echo '<td style="color: green;">OK</td>'."\n";
}
}
}
}
}
}
utf8izer('D:\\tmp_out2', 'D:\\tmp', array('java', 'jsp', 'htm', 'html', 'js', 'xml', 'js', 'xsl'));
?>
</table>