My (advertisement) site consists of 2 parts:
- One form wher people can register and put their advertisement in, including image upload (using chronoforms)
- One page where people can see the advertisements with images in a tabular form (using ChronoConnectivity).
This works very well, but one of the issues I have is the following:
If a advertiser decides not to upload images, in the table, the browser can (obviously) not find any image. Especially in IE, an ugly 'red cross' will be shown. Here I would like to add a default image (e.g. the logo of my website).
So I am looking for a way to say 'If no image is uploaded, use this default image'.
Is something like this possible, and how to do.
Hi Fishhead,
you can use Bob's code in the body area, straight forward!🙂
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Aargh ... not so easy:
Apparently, the 'file exists' command cannot cope w. a variable such as {foto}. Let me explain.
- The CE code for my image-filename is {foto},
- It is in my path components/com_chronocontact/uploads
- In the same directory, i have an image called 'default.jpg'.
- If, for a record in chronoconnectivity, {foto} is empty (the advertiser didn't upload an image), it should show the default image.
I created the following code:
<?php
if
(file_exists("components/com_chronocontact/uploads/{foto}"))
{
echo "<img src='components/com_chronocontact/uploads/{foto}' >";
} else {
echo "<img src='components/com_chronocontact/uploads/default.jpg' >";
}
?>
In this case, it always shows default.jpg, therewith saying that {foto} doesn't exists.
To try out, I changed the source as following:
<?php
if
(file_exists("components/com_chronocontact/uploads/default.jpg"))
{
echo "<img src='components/com_chronocontact/uploads/{foto}' >";
} else {
echo "<img src='components/com_chronocontact/uploads/default.jpg' >";
}
?>
Now, it shows the {foto} images (where available), proving that;
a) The code recognises the {foto} tag and can find the images.
b) The 'file_exists' command works well, and I have the right directory in which I look.
So the only conclusion I can make is that the file_exists command does not work w. the {foto} tag
Am I right or am I overseeing something, and how to solve?
Kind regards,
Remko.
Remko:
May I suggest another way to tackle this problem. If the user does not upload an image when they create their advertisement, load your default image into the table where their image would have been put.
George
Hi Remko,
you can try George's suggestion or replace {foto} with $row->foto in your code because the code is evaluated before the {field_name} formula is replaced!
Best regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.