I am trying to read all filenames and Base64 code from a file. I have now tested the following:
preg_match_all('/Content-Disposition:\sattachment;\sfilename="(.*)"\s+Content-Transfer-Encoding:\sbase64\s+(.*)/', $fileContent, $match, PREG_PATTERN_ORDER);
But I have two problems
- i get only the first line from the base64 code
- If I specify ---- in my regex at the end, because it should only output the base64 code until then (so that I get all files), it does not find any result at all.
I have found several posts here already, but have the same or similar problem with most of them.
$fileContent:
--------------(cut)
Content-Type: application/pdf; name="file 1.pdf"
Content-Disposition: attachment; filename="file 1.pdf"
Content-Transfer-Encoding: base64
JVBERi(cut)J
bWFnZQ0KI(cut)Az
IDYNC(cut)PRg0K
(cut)
--------------(cut)
Content-Type: application/pdf; name="file 2.pdf"
Content-Disposition: attachment; filename="file 2.pdf"
Content-Transfer-Encoding: base64
JVBERi(cut)J0eXBlIC9J
bWFnZQ0KIC(cut)L0hlaWdodCAz
NDM3DQogIC9MZW5(cut)Q0KICAvQml0c1BlckNvbXBvbmVudCA4DQogIC9Db2xv
--------------(cut)--
EDIT1: This works fine (php regex to get base64 string). I only have the problem that the range (-----) is also present in the match