Here is an easy way to add multiple images

A place to discuss and receive support for the Web Auction application.

Here is an easy way to add multiple images

Postby Nicole » Sun Dec 16, 2007 2:53 am

After much headbanging and unwillingness to really did into the code, I finally figured out how to EASILY have multiple images :-)

1. Edit database to allow input of more images. Add new fields to the product table as 'product_image_01' 'product_image_02' etc using the same values as 'product_image' until you have the max number of images you want to add to each product. (Interestingly it works without adding additional image MIME type rows. I don't know enough to address that or if they truly should be created.)

2. Edit the file tables/products/fields.ini file to add near the top of the file:

[product_image_01]
Type=container
allowed_extensions="jpg,gif,png"
visibility:list = hidden
visibility:list = hidden

[product_image_02]
Type=container
allowed_extensions="jpg,gif,png"
visibility:list = hidden
visibility:list = hidden

Repeat until you match the number of images you want.

3. Edit this same file in tables/products/fields.ini file to add near the BOTTOM of the file:

[product_image_mimetype_01]
visibility:list = hidden

[product_image_mimetype_02]
visibility:list = hidden
etc

4. Edit the file in templates/view_product.html template file to display these additional images. Because the forum is eating code, you'll have to stretch a little to accomplish this step.

Locate and copy/paste line that starts the image display and repeat as necessary:





etc.

5. Create a new directory for each new image you want to have in ->
tables/products/product_image_01
tables/products/product_image_02
etc. and CHMOD them to 777

6. Add your images. I don't know for sure, but I think files over 1MB get corrupted. Mine were anyway. So keep it light to be safe.

The app will not display broken image code if there isn't an image uploaded for that row... which is pretty dang slick because I was trying to outsmart it by adding code to check for NULL before displaying the image -- and it just wouldn't play nicely with me with 'echo'... Smarty either didn't like it or it ignored the code entirely. I assume it checks for NULL somewhere else. Yea!

So.. this is it. Everything else is just layout and perhaps some nifty javascripting.


Great app!


Aloha,
-Nicole
Nicole
 
Posts: 6
Joined: Sun Dec 16, 2007 2:25 am

Postby shannah » Sun Dec 16, 2007 9:13 pm

Thanks for posting this tutorial, Nicole. I'm sure it will be helpful to a lot of people.

A couple of notes:
(Interestingly it works without adding additional image MIME type rows. I don't know enough to address that or if they truly should be created.)

Yes. It will work without adding the mimetype columns, but these columns will help dataface in various places to work more smoothly with the images as it will help it to know that they are, in fact, images.

2. Edit the file tables/products/fields.ini file to add near the top of the file:
...

3. Edit this same file in tables/products/fields.ini file to add near the BOTTOM of the file:


It actually doesn't matter whether you add these to the top or bottom of the file.

The app will not display broken image code if there isn't an image uploaded for that row

This may have been a stroke of luck with your browser. A good way to check for nulls in your template is just to use an {if} tag.
e.g.
Code: Select all
{if $record->val('product_image_01')} ... {/if}


Thanks and best regards

Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Nicole » Sun Dec 16, 2007 10:08 pm

Quote:

The app will not display broken image code if there isn't an image uploaded for that row

This may have been a stroke of luck with your browser. A good way to check for nulls in your template is just to use an {if} tag.
e.g.



You're right.. Was my browser (Firefox) degrading nicely. IE displayed broken images.

view_product.html file to check for images before displaying:

{if $record->val('product_image_01')}

{/if}

{if $record->val('product_image_02')}

{/if}

Thanks for that {if} code, Steve! Works like a champ!

Aloha,
Nicole
Nicole
 
Posts: 6
Joined: Sun Dec 16, 2007 2:25 am

Postby r0n2990 » Tue Dec 18, 2007 3:23 pm

Hey,

I love the code but I am trying to use it on the home page and its giving me an error about how it does not like it a null. The thing is I am using the same code that I used on the product page.

Any suggestions?

-Cam
r0n2990
 
Posts: 9
Joined: Thu Dec 13, 2007 5:02 am

Postby r0n2990 » Tue Dec 18, 2007 6:07 pm

I figured it out,

Code: Select all
{if $product->val('product_image') != NULL}
...

{/if}


That worked nicely for me.
r0n2990
 
Posts: 9
Joined: Thu Dec 13, 2007 5:02 am


Return to Web Auction Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved