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?

By Chris - October 6, 2010

Hi Perch,

Oh, I thought you were going with my suggestion of having an "Attachments" section which would own the uploads. It seems you're directly selecting uploads. I'm glad you figured out how to fix things to work with your approach. :)

If you're getting uploads directly from the uploads table, there are a few fields which won't be defined for you. You can see which "pseudo-fields" are added (and how they're added) if you look in cmsAdmin/lib/upload_functions.php at the getUploadRecords() function.

Specificially, to generate the 'filename' pseudo-field, try this:

<?php echo pathinfo($attachment['filePath'], PATHINFO_BASENAME) ?>

Does that help? Please let me know if you have any questions.
All the best,
Chris
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/