Code Help

5 posts by 2 authors in: Forums > CMS Builder
Last Post: September 27, 2010   (RSS)

Hello, Folks -

I wonder if someone would be so good as to give me some much-needed advice. I'm trying to set-up a simple download counter for a client (which will be run alongside CMSB). The aim is to count the number of times a range of attachments are downloaded.

In order to set-up the download counter I need to input the list of files to be monitored. Typically these would be added manually using the following format:

$settings['allowedownloads'] = array(
"test.zip",
"another_file.pdf",
"download_me.pdf"
);


I want to replace this list (in red) with data pulled straight from CMSB. Sounds simple. The trouble is, although I am able to compile the list of files, somehow it isn't in the right format for the script.

I assumed it should be something like this...

<?php foreach ($itemRecords as $record): ?>
<?php foreach ($record['attachments'] as $attachment): ?>
<?php $files[] = $attachment['filename']; ?>
<?php endforeach ?>
<?php endforeach ?>

$settings['allowedownloads'] = $files;


I've tried a host of different things - including imploding and exploding the array/string - but it just won't work.

What am I doing wrong?!

:0S

Perch

Re: [Perchpole] Code Help

By Jason - September 27, 2010

Hi Perch,

There isn't anything obviously wrong in your code. Do you get an error message?

Was the script working when you created the list manually?

add this this code:

$settings['allowedownloads'] = $files;
showme($settings);exit;


This debugging code will show you all the contents of the $settings array and then exit the script.

It should display something like this:
Array(
[alloweddownloads] =>
Array (
[0] => test.zip
[1] => another_file.pdf
[2] => download_me.pdf
)
)

Let me know what it outputs. Also, is there some documentation on your counting script that describes what format the data needs to be in?

Let me know and I can take a closer look into this issue.

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Perchpole] Code Help

By Jason - September 27, 2010

Hi Perch,

Some servers are a little more picky about header information than others. What was probably happening is there was a hidden character (probably a space or something) between the 2 php blocks. The server interpreted this as information that needs to be outputted to the browser. One you start outputting information to the screen,you can no longer change header information.

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/

Re: [Jason] Code Help

Once you start outputting information to the screen,you can no longer change header information.


A-ha! That's a valuable bit of info to commit to memory.

Thanks again for your help.

:0)

Perch