Exemplo n.º 1
0
/**
 * Attach files from some array to $to object
 * 
 * - $from keys : - path
 *                - filename
 *                - type
 *
 * @param array $from
 * @param ProjectObject $to
 */
function attach_from_array(&$from, &$to)
{
    $attached = 0;
    if (is_foreachable($from)) {
        foreach ($from as $file) {
            $attach = $to->attachFile($file['path'], $file['filename'], $file['type']);
            if (is_error($attach) || !$attach) {
                $to->clearPendingFiles();
                return $attach;
            } else {
                $attached++;
            }
            // if
        }
        // foreach
    }
    // if
    return $attached;
}