Linking to Uploads Across Multiple Documents?

25 posts by 3 authors in: Forums > CMS Builder
Last Post: October 7, 2010   (RSS)

Chris -

Again, very nearly. I'm just getting an "Invalid argument supplied for foreach()" error for the foreach loop...

<?php foreach($attachment['uploads'] as $upload): ?>

I think the problem is that $attachment returns a single upload record...

Array
(
[num] => 37
[order] => 3
[createdTime] => 2008-06-27 01:16:50
[tableName] => tag_articles
[fieldName] => attachments
[recordNum] => 1
[preSaveTempId] =>
[filePath] => /mypath/assets/Scottish_2008.pdf
[urlPath] => /assets/Scottish_2008.pdf
etc..........


:o+

Perch

Re: [Perchpole] Linking to Uploads Across Multiple Documents?

<ul>
<?php foreach($news as $record): ?>
<li>
<b><?php echo $record['title'] ?></b><br />

<?php if ($record['attachment']): ?>
Attachments:
<ul>
<?php foreach(explode("\t", trim($record['attachment'])) as $attachmentNum): ?>
<?php $attachment = $attachmentsByNum[$attachmentNum] ?>
<?php foreach($attachment['uploads'] as $upload): ?>
<a href="<?php echo $upload['urlPath'] ?>"><?php echo $upload['filename'] ?></a><br/>
<?php endforeach ?>
<?php endforeach ?>
</ul>
<?php endif ?>
</li>
<?php endforeach ?>
</ul>


In fact if you just take out the code in red it works! You need to replace each instance of "$upload" with "$attachment" but it seems to do the trick.

Thanks chaps. Your help was very much appreciated.

:0)

Perch

PS. There is no ['filename'] for uploads only the pseudo [_filename] - but I'm not sure how to define it....
Brilliant -

Thank you, both, very much for this.

Just one last question on this: Currently, in the section editor, I'm using a standard list arrangement to pull the uploads together, using num for values and urlPath for the label.

Would it be possible to construct an advanced MySQL query using PATHINFO_BASENAME? This should result in a list of filenames - not url paths - which would be far easier to read.

:0)

Perch

Re: [Perchpole] Linking to Uploads Across Multiple Documents?

By Jason - October 7, 2010

Hi Perch,

You can get the file name from the urlPath like this assuming the folder the images are in is called uploads:
SELECT num, SUBSTRING(urlPath FROM (LOCATE('/uploads/',urlPath)+9))
FROM `<?php echo $TABLE_PREFIX ?>uploads`


Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/