Uploading documents for download

10 posts by 2 authors in: Forums > CMS Builder
Last Post: May 9, 2010   (RSS)

By svsanchez - May 5, 2010

Hello, I became a happy customer after purchasing AM so I decided to try CMS Builder for 2 of my clients thinking it would be as easy to work with as AM, but I'm really confused by the program. I'm sure that when I finally understand how it works it will be a great product, but for now I need some guidance in creating a section where my customer can upload documents (in pdf, word, excel, etc...) and listing them with a title, description, an icon depending on the type of file and allowing users to download the documents.

I created an html file showing how it should look here: http://www.observatoriodsan.org/dummy.htm

Can you tell me how to do this please!

Thank you!
Sven Sanchez

www.deguate.com

Re: [svsanchez] Uploading documents for download

By gkornbluth - May 5, 2010 - edited: May 5, 2010

Hi,

Working with uploads is easier than you probably think they are at this point.

Here’s the basic process, modified from some of the recipes in my CMSB Cookbook http://www.thecmsbcookbook.com

First, in the admin > section editor area of your CMSB interface, click on “create new menu” to create a multi-record editor called PDF to store the information about your pdf files.

You’ll need at least three fields in this editor.

A “title” text field for the link
A “content” text box for the description
And an “upload” field for the actual pdf file

For now it will be easier to use the existing "title" and "content" fields that were created by default. Just click "modify" to change the field type for “content” to a text box field and re-save it.

You’ll need to create a new field for the actual PDF upload and call that field PDF. You’ll want to change some of the values in the input validation area.

For now, delete all the file extensions allowed and type in "pdf" (lower case, no double quotes and no period before the extension) if you want to allow other types of documents, just add these extensions to the list, separated by commas.

Change the maximum uploads to 1
Change the maximum upload size to a more reasonable number, say 1000Kbytes
Uncheck the "resize" and "create thumbnail" boxes
Remove the words "title" and "caption" from the" info1" and "info2" fields and click "save" and then on "save details".

Then in the menu, click on the PDF editor you just created and then on “create” to create your first record and upload a test PDF (or other type of document).

Fill out the information for the title and content fields.
Save the record and create a second test record and save it as well.

Now go to the Admin > code generator, choose the PDF as the section and list page as the viewer type.

Leave everything else as it is and click on show code.

Copy the code before the "head" tag to your dummy html page, replacing everything before the "head" tag. and change the extension of the page to .php as in “dummy.php”

In the body, where you want to show the list of PDF files, insert the following code:
<?php foreach ($pdfRecords as $record): ?>
<?php foreach ($record['pdf'] as $upload): ?>
<a href="<?php echo $upload['urlPath'] ?>"> <?php echo $record['title'] ?></a><br />
<?php echo $record['content'] ?><br />
<?php endforeach ?>
<?php endforeach ?>


That should get you started.

You can style the page the same way that you would any html page using CSS.

After you get the hang of this, you can also change the image from the PDF image to other types of images using "IF statements".

Good luck.

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Uploading documents for download

By svsanchez - May 5, 2010

Hello, thank youy for your instructions, I tried them however it didn't work. I am getting this error message:

Notice: Undefined index: gestion_del_conocimiento in /home/observat/public_html/dummy.php on line 53 Warning: Invalid argument supplied for foreach() in /home/observat/public_html/dummy.php on line 53

Here's the link: http://www.observatoriodsan.org/dummy.php
Sven Sanchez

www.deguate.com

Re: [svsanchez] Uploading documents for download

By gkornbluth - May 5, 2010

Sorry it didn't work as planned,

Let's start simple.

If you paste the entire code generator code into a blank test.php document does that work at all?

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Uploading documents for download

By svsanchez - May 5, 2010

Hello, when I create a blank page with the code (or a page with the design on it) and paste the code generated by the Code Generator it gives me no error, but when I replace the code generated by the Code Generator with the code you sent me I get the error. Here's the blank page I created with the code you sent me:

http://www.observatoriodsan.org/gestiondetail.php
Sven Sanchez

www.deguate.com

Re: [svsanchez] Uploading documents for download

By gkornbluth - May 5, 2010 - edited: May 5, 2010

And you created some records as samples? I'll mock up a page and see what I get
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [svsanchez] Uploading documents for download

By gkornbluth - May 5, 2010

Hi svsanchez ,

If you take a look at http://artistsofpalmbeachcounty.org/PDF_Test.php you'll see the result of following the instructions I offered above, copying the entire code generator code, followed by pasting in the body code in my suggestion. They both seem to work.

Check everything again and I'm sure that you'll find the discrepancy.

Good luck,

Don't get too discouraged.


Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Uploading documents for download

By svsanchez - May 9, 2010

Hello, I think I figured it out, the problem seems to have been the "type" of field. You said it had to be "Text Box" and I had it as "Wysiwyg". Changing that corrected the issue!

Now on the "if" statements to show a "PDF" icon, "Word" icon, etc... can you help me on doing that?

Thank you again!
Sven Sanchez

www.deguate.com

Re: [svsanchez] Uploading documents for download

By gkornbluth - May 9, 2010 - edited: May 9, 2010

Hi svsanchez,

Glad it's working. WYSIWYG fields can be a bit tricky.

You could upload all the icons you want to use into a folder called “images” in your sites root directory.

Then, inside the upload foreach loop, where you want to show the icon, you could use something like the following:

<?php if ($upload['extension'] == 'pdf'): ?>
<img src="http://www.your_site/images/pdf.jpg" width="nn" height="xx" />
<?php if ($upload['extension'] == 'doc'): ?>
<img src="http://www.your_site/images/doc.jpg" width="nn" height="xx" />
<?php else: ?>
<img src="http://www.your_site/images/other_format.jpg" width="nn" height="xx" />

<?php endif ?>


Hope that gets you going.

Best,

Jerry Kornbluth
<?php if ($upload['extension'] == 'swf'): ?>
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php