in my database I store a filePath containing all the uploaded documents. It looks something like the following
C:\Users\User\Desktop\Portal\Portal\public\uploads\Weekly Complete Jobs.docx&&&C:\Users\User\Desktop\Portal\Portal\public\uploads\Wish List.docx&&&
So I have separated each filepath by using
&&&
In PHP, I then explode this filepath and then I want to loop each path and add it to an array. At the moment, I have something like this
$attachments = array();
if(!empty($this->project->dsReportingDoc->filePath)) {
$string = explode("&&&", $this->project->dsReportingDoc->filePath);
foreach($string as $key=>$path){
if(!empty($path)){
$attDoc = chunk_split(base64_encode(file_get_contents($path)));
$attachments = [(
array(
"Id" => $key,
"Version" => $key,
"File" => array(
"Name" => $path,
"Content" => $attDoc
)
)
)];
}
}
}
The problem I am having is that it only seems to be adding the last path to the array because I think the others are being overriden.
How can I get them all added to this array?
Thanks