Judah Raine
Total posts: 332
31 Oct 2012 10:09

I'm posting a new question on this as the other one is long and I have printed it out, but it relates to image field which does not have the upload ability as yet.

As I need my users to upload the file, I would of necessity have to work with uploads field. I need, however, for this to display as an image in the article, with preset sizes.

I have copied the output file as follows with my reasoning on each aspect, and I would appreciate it if you could advise whether I'm correct or not.

files AS $i => $file):?>
    **<tr class="cat-list-row<?php echo $k = 1 - $k; ?>">

        <td width="1%"><?php echo $i+1;?></td>

        <td>**

As I do not need a list of files I assume I can delete the above lines?

            <a 

            <?php 

            $class = '';

            **if($this->params->get('params.show_in_browser', 0))

**

I'm assuming that the above is actually where it begins the output instruction, and below offers the various options?

{

                switch ($this->params->get('params.show_target', 0))

                {

                    case 0:

                        echo ' target="_blank" ';

                        echo ' href="'.$file->url.'"';

                        break;



                    case 1:

                        echo ' onclick="popUpFile'.$this->id.'(\''.$file->url.'\');return false;" ';

                        echo ' href="javascript:void(0);"';

                        break;



                    case 2:

                        echo ' href="'.$file->url.'"';

                        $class = ' class="modal"';

                        break;



                    case 3:

                        echo ' href="'.$file->url.'"';

                        break;

                }

            }

            else

            {

                echo ' target="_blank" ';

                echo ' href="'.$file->url.'"';

            }

            ?>  

            >

As the above options relate to showing the file once the link is clicked in the list, am I correct in saying that I do not need these?

My thought is that I should be rewriting echo ' href="'.$file->url.'"';

with whatever is needed to "convert" the attachment into an article image??

I have once again Googled extensively and cannot find the php needed to output an attachment (upload) file as an image and so once again I need a little assistance when you have a moment.

Again, as I do not need title, description, hits, etc, I suppose I could just delete the rest?

            <?php echo ($this->params->get('params.allow_edit_title', 0) && $file->title ? $file->title : $file->realname);?>

            </a>

            <?php if($this->descr && $file->description):?>

                <p><?php echo $file->description;?></p>

            <?php endif;?>

        </td>



        <?php if($this->hits):?>

            <td width="1%"><?php echo (int)$file->hits?></td>

        <?php endif;?>



        <?php if($this->size):?>

            <td width="1%" nowrap="nowrap"><?php echo HTMLFormatHelper::formatSize($file->size);?></td>

        <?php endif;?>

Last Modified: 02 Mar 2014


Sackgesicht VIP
Total posts: 1,636
31 Oct 2012 18:08

Judah,

why not using the gallery field, which let you upload images and display them based on parameters? It will also take care of creating thumbnails etc.

Gallery Field

Of course, you can also create an output template for the uploads field.

If you only allow the upload of 1 file (Parameter "Maximum files count limit"), you will get the URL through

this->files[0]->url

the most minimalistic template to display an image with the uploads field might be something like this:

<?php if($num = count($this->files)):?>

<img src="/<?php echo $this->files[0]->url ?>" />

<?php endif;?>

<?php return; ?>

This can be refined by adding alt, hight, width attributes, aligning the image etc...

Hope this helps :)


Judah Raine
Total posts: 332
01 Nov 2012 04:12

Thank you for this, I will work on it later today - I had thought of the gallery field but as it's single images I thought it would be simpler to just use this.

Powered by Cobalt