0

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

1
  • 1
    Looks like you overwrite $attachments, try $attachments[] Commented Dec 11, 2015 at 15:14

1 Answer 1

2
$attachments[] = 
    array(
        "Id" => $key,
        "Version" => $key,
        "File" => array(
            "Name" => $path,
            "Content" => $attDoc
        )
    )
;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.