Pb de preg_match !!! au secour !!!!!!!!!

Signaler
Messages postés
144
Date d'inscription
mercredi 16 juin 2004
Statut
Membre
Dernière intervention
22 mars 2006
-
Messages postés
10839
Date d'inscription
lundi 24 février 2003
Statut
Modérateur
Dernière intervention
2 mars 2010
-
salut,

j'ai un probleme dans mon code , ca viens surement de la fontion preg_match
mon application vas chercher dans un repertoire tout les fichier qui sont de type .TXT et ensuite inserre dans une base mysql pour chacun son nom, sa date de creation, da date de modification et sa taille.

voici mon code :

<?php


function testdate($date)
{
return date("D/M/Y H:i:s",$date);
}

$rep = "/var/awstats/data/";
$dir = opendir($rep);
$j=0;


while (false !($f readdir($dir)))
{
echo "_test while num 1_";

if(is_file($rep.$f))
{
echo "_test if num 1_";
echo


// je pensse que mon erreur vien de la !!!
if (preg_match("/.txt$/",$f))
{
echo "_test if num 2_";
echo "_test_";
echo $f;
echo "_test_";

while($i<sizeof($f))
{

echo "_test while num 3 affichage !!!_";
/*
$fileInfo = stat($rep.$f) ;
echo '' ;
print_r($fileInfo) ;
echo '

';
*/
$nom=$f[$i];
echo $nom;
$taille=filesize($rep.$f[$i]);
echo $taille;
$date_crea=testdate(filectime($rep.$f[$i]));
echo $date_crea;
$date_modif=testdate(filemtime($rep.$f[$i]));
echo $date_modif;

$i= $i+1;


// requette d'insertion
//$query = 'INSERT INTO fichiers (nom,taille,date_crea,date_modif) VALUES ($nom,$taille,$date_crea,$date_modif));';
//$result = mysql_query($query);


//return $result;

}
}

}

}


?>

Message d'erreur :

Parse error: parse error, unexpected T_IF, expecting ',' or ';' in /home/fuk/public_html/insert_file3.php on line 21

merci de m'aidé

vive PHP !!!, vive la prog !!!

2 réponses

Messages postés
144
Date d'inscription
mercredi 16 juin 2004
Statut
Membre
Dernière intervention
22 mars 2006

appres legere modif du if (preg_match("/.txt$/",$f))

ca marche toujours pas ! :-(

mon code ( appres petite modif) :

<?php


function testdate($date)
{
return date("D/M/Y H:i:s",$date);
}

$rep = "/var/awstats/data/";
$dir = opendir($rep);
$j=0;


while (false !($f readdir($dir)))
{
echo "_test while num 1_";

if(is_file($rep.$f))
{
echo "_test if num 1_";


if(preg_match("/.txt$/",$f))
{
echo "_test if num 2_";
echo "_test_";
echo $f;
echo "_test_";

while($i<sizeof($f))
{

echo "_test while num 3 affichage !!!_";
/*
$fileInfo = stat($rep.$f) ;
echo '' ;
print_r($fileInfo) ;
echo '

';
*/
$nom=$f[$i];
echo $nom;
$taille=filesize($rep.$f[$i]);
echo $taille;
$date_crea=testdate(filectime($rep.$f[$i]));
echo $date_crea;
$date_modif=testdate(filemtime($rep.$f[$i]));
echo $date_modif;

$i= $i+1;


// requette d'insertion
//$query = 'INSERT INTO fichiers (nom,taille,date_crea,date_modif) VALUES ($nom,$taille,$date_crea,$date_modif));';
//$result = mysql_query($query);


//return $result;

}
}

}

}


?>



message d'erreur :

_test while num 1__test if num 1__test if num 2__test_awstats052004.www.3ds.com.txt_test_
Notice : Undefined variable: i in /home/fuk/public_html/insert_file3.php on line 28
_test while num 3 affichage !!!_
Notice: Undefined variable: i in /home/fuk/public_html/insert_file3.php on line 38
a
Notice: Undefined variable: i in /home/fuk/public_html/insert_file3.php on line 40

Warning: filesize(): Stat failed for /var/awstats/data/a (errno =2 - No such file or directory) in /home/fuk/public_html/insert_file3.php on line 40

Notice: Undefined variable: i in /home/fuk/public_html/insert_file3.php on line 42

Warning: filectime(): Stat failed for /var/awstats/data/a (errno= 2 - No such file or directory) in /home/fuk/public_html/insert_file3.php on line 42
Wed/Dec/1969 19:00:00
Notice: Undefined variable: i in /home/fuk/public_html/insert_file3.php on line 44

Warning: filemtime(): Stat failed for /var/awstats/data/a (errno =2 - No such file or directory) in /home/fuk/public_html/insert_file3.php on line 44
Wed/Dec/1969 19:00:00
Notice: Undefined variable: i in /home/fuk/public_html/insert_file3.php on line 47
_test while num 1__test if num 1__test while num 1__test if num 1__test if num 2__test_awstats102004.www.3ds.com.txt_test__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test if num 2__test_awstats092004.www.3ds.com.txt_test__test while num 1__test if num 1__test if num 2__test_awstats062004.www.3ds.com.txt_test__test while num 1__test if num 1__test if num 2__test_awstats012005.www.3ds.com.txt_test__test while num 1__test if num 1__test if num 2__test_awstats012005.delivery.3ds.com.txt_test__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test if num 2__test_awstats042004.www.3ds.com.txt_test__test while num 1__test if num 1__test if num 2__test_awstats072004.www.3ds.com.txt_test__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test while num 1__test if num 1__test if num 2__test_dnscachelastupdate.delivery.3ds.com.txt_test__test while num 1__test if num 1__test while num 1__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test if num 2__test_awstats022005.delivery.3ds.com.txt_test__test while num 1__test if num 1__test while num 1__test if num 1__test if num 2__test_dnscachelastupdate.www.3ds.com.txt_test__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test if num 2__test_awstats022005.www.3ds.com.txt_test__test while num 1__test if num 1__test if num 2__test_awstats112004.www.3ds.com.txt_test__test while num 1__test if num 1__test if num 2__test_awstats032004.www.3ds.com.txt_test__test while num 1__test if num 1__test while num 1__test if num 1__test if num 2__test_dnscachelastupdate.plm.3ds.com.txt_test__test while num 1__test if num 1__test if num 2__test_awstats122004.delivery.3ds.com.txt_test__test while num 1__test if num 1__test while num 1__test if num 1__test if num 2__test_awstats082004.www.3ds.com.txt_test__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1__test while num 1__test if num 1_

vive PHP !!!, vive la prog !!!
Messages postés
10839
Date d'inscription
lundi 24 février 2003
Statut
Modérateur
Dernière intervention
2 mars 2010
25
Hello,



ici : while($i<sizeof($f))



Tu fais appel a $i, mais il n'est pas defini a ce moment la. Il faut
que $i comporte une valeur ($i=0 par exemple) avant de t'en servir dans
la condition de ton while.