Display link when file exists

nams09 20 Apr, 2015
Hello!

I'm using the following code to display a link only when the file exists:

<?php
if ($form->data["Banner2"]["documento_banner"] !== ' ') {
  echo "<a href='*my path*/com_chronoforms5/chronoforms/uploads/banner2/{Banner2.documento_banner}'>Descargar archivo</a><br>";
} else {
  echo "No file";
}
?>


The problem is it still displays the line "Descargar archivo" even when the file doesn't exist instead of displaying "No file", it's like the "else" wasn't there.

Can you help me please?
GreyHead 21 Apr, 2015
Hi nams09,

You are checking !== ' ' - and there is a space between the ' '. It should be '' with no space, or perhaps better:
<?php
$message = 'No file';
if ( !empty($form->data['Banner2']['documento_banner']) ) {
  $image_uri = JURI::root().'/com_chronoforms5/chronoforms/uploads/banner2/'.$form->data['Banner2']['documento_banner'];
  $message = "<a href='{$image_uri }'</a><br>";
} 
echo $message;
?>

Bob
nams09 21 Apr, 2015
Hi Greyhead!

Thanks for your reply. Unfortunately this didn't work, looks like it's not recognizing the !empty command, which is why I used !== ' ' instead. Any idea of what could be the problem?
nams09 21 Apr, 2015
Could it be an issue if I'm using this code in the View Action?
GreyHead 21 Apr, 2015
Answer
Hi nams09,

The !empty() code should work correctly.

I notice that this is the ChronoConnectivity forum but this looks like a ChronoForms question - which is it?

If it is CF then $form->data will work, if it is CC then you probably need $row

Bob
nams09 21 Apr, 2015
It's actually Chronoconnectivity, I used $row and it works now, thanks! 😀
This topic is locked and no more replies can be posted.