[RESOLU] Rechercher un texte entre deux double cote

Eléphanteau du PHP | 20 Messages

28 mai 2013, 17:58

Voici mon code

<?php
echo 'Hello Vous etes sur la page Upload.php'."<br />";

$corp = '';
$fh = @fopen('php://upload', 'r');
if ($fh)
{
while (!feof($fh))
{
$s = fread($fh, 1024);
if (is_string($s))
{
$corp .= $s;
}
}
fclose($fh);
}
print("PHP Input Stream\n$corp\n\n");

$body = http_get_request_body();
print("http_get_request_body()\n$body\n\n");
$date = date("-d-m-Y");
$heure = date("-H\hi");

$nom_file = "fichier$date$heure.txt";
// creation du fichier
$f = fopen($nom_file, "x+");
// ecriture
fputs($f, $body );
// fermeture
fclose($f);
?>

et le resultat qui biensur le resultat change pour l'instant le nom du fichier est : fichierdataheur.txt et le probleme c'est que le veritable nom du fichier que je dois lui donner voir en rouge est dedant

Message-ID: <2875.420513fdfdf97386172.JavaMail.382472-a@AAYYERP122885>
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_754FFF_78AA845_128675464898883.1366454545297386162"

------=_754FFF_78AA845_128675464898883.1366454545297386162
content-type: application/octet-stream
content-transfer-encoding: binary
Content-Disposition: form-data; name="_754FFF_78AA845_128675464898883.1366454545297386162.HTE"; filename="client_7845845_128675464898883.1366454545297386162.xml"

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AcknowledgementDocument DtdRelease="0" DtdVersion="5">
<DocumentIdentification v="client_7845845_128675464898883.1366454545297386162"/>
<DocumentDateTime v="2013-04-12T16:52:11Z"/>
<SenderIdentification codingScheme="A01" v="client_7845845_128675464898883"/>
<SenderRole v="A04"/>
<ReceiverIdentification codingScheme="A01" v="17X100FFFA100R00182"/>
<ReceiverRole v="A06"/>
<ReceivingDocumentIdentification v="04424_20130412ZKLT102513"/>
<ReceivingDocumentVersion v="4"/>
<ReceivingDocumentType v="A54"/>
<Reason>
<ReasonCode v="A01"/>
<ReasonText v="Message fully accepted"/>
</Reason>
</AcknowledgementDocument>
------=128675464898883.1366454545297386162
content-type: text/plain
Content-Transfer-Encoding: 7bit

Mammouth du PHP | 619 Messages

28 mai 2013, 19:41

Re,

ta variable c'es body pas boby
<?php
//on recherche file="" dans la variable $boby si on trouve un résultat on le sort dans un tableau $matches
if(preg_match('#file="(.+)"#isU',$body,$matches)){
print_r($matches);
//echo $matches[1];
}
else{
echo 'Aucun';
}
?>

Eléphanteau du PHP | 20 Messages

29 mai 2013, 09:53

Re,

J'ai corrigé mais il me répond toujours la même chose, que $matches correspond a Array

Seb

Mammouth du PHP | 619 Messages

29 mai 2013, 09:55

ok j'ai pas fait attention c'est pareil il a une erreur c'est filename et non file
<?php
//on recherche file="" dans la variable $boby si on trouve un résultat on le sort dans un tableau $matches
if(preg_match('#filename="(.+)"#isU',$body,$matches)){
print_r($matches);
//echo $matches[1];
}
else{
echo 'Aucun';
}
?>

Eléphanteau du PHP | 20 Messages

29 mai 2013, 10:01

OK ça aussi je l'ai vu et corrigé :( mais j'ai toujours le même résultat.

Seb

Mammouth du PHP | 619 Messages

29 mai 2013, 10:06

il doit avoir un souci avec la balise body car moi avec ce code
<?php
$body='
Message-ID: <2875.420513fdfdf97386172.JavaMail.382472-a@AAYYERP122885>
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_754FFF_78AA845_128675464898883.1366454545297386162"

------=_754FFF_78AA845_128675464898883.1366454545297386162
content-type: application/octet-stream
content-transfer-encoding: binary
Content-Disposition: form-data; name="_754FFF_78AA845_128675464898883.1366454545297386162.HTE"; filename="client_7845845_128675464898883.1366454545297386162.xml"

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AcknowledgementDocument DtdRelease="0" DtdVersion="5">
<DocumentIdentification v="client_7845845_128675464898883.1366454545297386162"/>
<DocumentDateTime v="2013-04-12T16:52:11Z"/>
<SenderIdentification codingScheme="A01" v="client_7845845_128675464898883"/>
<SenderRole v="A04"/>
<ReceiverIdentification codingScheme="A01" v="17X100FFFA100R00182"/>
<ReceiverRole v="A06"/>
<ReceivingDocumentIdentification v="04424_20130412ZKLT102513"/>
<ReceivingDocumentVersion v="4"/>
<ReceivingDocumentType v="A54"/>
<Reason>
<ReasonCode v="A01"/>
<ReasonText v="Message fully accepted"/>
</Reason>
</AcknowledgementDocument>
------=128675464898883.1366454545297386162
content-type: text/plain
Content-Transfer-Encoding: 7bit
';
if(preg_match('#filename="(.+)"#isU',$body,$matches)){
print_r($matches);
//echo $matches[1];
}
else{
echo 'Aucun';
}
?>

j'ai bien Array ( [0] => filename="client_7845845_128675464898883.1366454545297386162.xml" [1] => client_7845845_128675464898883.1366454545297386162.xml )

sinon essaie ceci
<?php
$content=file_get_contents($nom_file);
if(preg_match('#filename="(.+)"#isU',$content,$matches)){
print_r($matches);
//echo $matches[1];
}
else{
echo 'Aucun';
}
?>

Eléphanteau du PHP | 20 Messages

29 mai 2013, 10:41

En faite ton code fonctionne lorsque tu mets tout le texte dans body, j'ai fait le même test ça donne bien
Array ( [0] => filename="client_7845845_128675464898883.1366454545297386162.xml" [1] => client_7845845_128675464898883.1366454545297386162.xml )

J'ai essayé avec ton 2ème code, ça marche pas.

Seb

Eléphanteau du PHP | 20 Messages

29 mai 2013, 10:48

en faite lors de la création du fichier, il portera le nom qu"il a trouvé dans filename= c'est "client_7845845_128675464898883.1366454545297386162.xm"

Seb

Mammouth du PHP | 619 Messages

29 mai 2013, 11:00

ok dit moi $body ne serai pas un tableau ? ^^ fait un print_r($body); et affiche le résultat ici :)

Eléphanteau du PHP | 20 Messages

29 mai 2013, 11:20

:D :D :D :D :D :D :D
C'est bon ça marche et comme toujours c'est tout bête.... :evil: :evil:
if(preg_match('#filename="(.+)"#isU',$body,$matches)){
print_r($matches);
}
else{
echo 'Aucun';
}
Le code était bon depuis le départ
mais c'est a la récupération de la variable qu'il fallait ajouter $matches[1] moi je mettais que $matches
// creation du fichier
$f = fopen($matches[1], "x+");
// ecriture
fputs($f, $body );
// fermeture
fclose($f);
:priere: Mille excuse car je t'ai fait perdre beaucoup de temps pour rien. Merci aussi pour ta patience.

Seb

Mammouth du PHP | 619 Messages

29 mai 2013, 11:27

Ok parfait pourtant j'ai bien mi

print_r($matches); cela affiche un array avec toutes les valeurs
//echo $matches[1]; //ici pour recup ta valeur :p