AttachmentManager::getFiles PHP Method

getFiles() public method

Get all the files and directories of a relative path.
public getFiles ( string $p_articleId, $p_languageId = null ) : array
$p_articleId string
return array of file and path information. array('url'=>'full url', 'storage'=>'full file path')
    function getFiles($p_articleId, $p_languageId = null)
    {
        $files = array();
        if ($this->isValidBase() == false) {
            return $files;
        }
        $articleAttachments = ArticleAttachment::GetAttachmentsByArticleNumber($p_articleId, $p_languageId);
        foreach ($articleAttachments as $articleAttachment) {
            if (!$this->m_config['validate_files']) {
                $file['attachment'] = $articleAttachment;
                $file['url'] = $articleAttachment->getAttachmentUrl();
                $file['storage'] = $articleAttachment->getStorageLocation();
                $files[$articleAttachment->getAttachmentId()] = $file;
            }
        }
        ksort($files);
        return $files;
    }

Same methods

AttachmentManager::getFiles ( string $p_articleId, $p_languageId = null, $p_filter = true ) : array

Usage Example

Example #1
0
require_once('config.inc.php');
require_once($GLOBALS['g_campsiteDir']."/$ADMIN_DIR/lib_campsite.php");
require_once('classes/AttachmentManager.php');

$manager = new AttachmentManager($AMConfig);

$languageSelected = (isset($_REQUEST['language_selected']) && is_numeric($_REQUEST['language_selected']))
    ? $_REQUEST['language_selected'] : null;
$articleId = (isset($_REQUEST['article_id']) && is_numeric($_REQUEST['article_id']))
    ? $_REQUEST['article_id'] : null;

// Get the list of files and directories
$list = array();
if (!is_null($articleId)) {
    $list = $manager->getFiles($articleId, $languageSelected);
}


/**
 * Draw the files in a table.
 */
function drawFiles($list, &$manager)
{
    global $languageSelected, $Campsite;

    $counter = 0;
    foreach($list as $entry => $file)
    {
        $counter++;
        $languageId = ($file['attachment']->getLanguageId()) ? $file['attachment']->getLanguageId() : $languageSelected;