Jump to content

Delete the image when uploading the helper form


Recommended Posts

Hi.all my friends

i am upload the image file using helper form like as

array(
'type' => 'file',
'desc' => sprintf($this->l('icon. Maximum image size: %s.'), ini_get('upload_max_filesize')),
'label' => $this->l('icon'),
'display_image' => true,
'name' => 'ICON_FILEDS',
'thumb' => '../modules/'.$this->name.'/views/img/'.Configuration::get('ICON_FILEDS'),
),

its working the and display image correct but my problem is how to delete that image when one time is uploaded

see the image.

thanks

 

 

post-558480-0-90073400-1468242346_thumb.png

Link to comment
Share on other sites

I think you'll need to override the TPL file and add a Delete button yourself. At least that's what I did for my Image/Video Gallery module. For example, I have the following code in modules/gallerync/views/templates/admin/gallerync_galleries/helpers/form/form.tpl (change gallerync to your module name and gallerync_galleries to the controller's table name):

{block name="input"}
    {if $input.type == 'file' && $input.name == 'cover'}
        {if isset($input.display_image) && $input.display_image}
            {if isset($fields_value.cover) && $fields_value.cover}
                <div id="image">
                    {$fields_value.cover}
                    <p>{l s='File size' mod='gallerync'} {$fields_value.cover_size|intval}kb</p>
                    <a class="btn btn-default" href="{$current|escape:'htmlall':'UTF-8'}&{$identifier|escape:'htmlall':'UTF-8'}={$form_id|intval}&token={$token|escape:'htmlall':'UTF-8'}&deleteCover=1" style="margin-bottom:12px">
                        <i class="icon-trash"></i> {l s='Delete' mod='gallerync'}
                    </a>
                </div>
            {/if}
        {/if}
{/block}

This will add the file size and a "Delete" button. I put the following code in the renderForm() function of modules/gallerync/controllers/admin/AdminGalleryNCGalleriesController.php to create the $fields_value.cover and $fields_value.cover_size Smarty variables:

        $this->fields_value = array(
            'cover' => $cover ? $cover : false,
            'cover_size' => $cover ?
                filesize(_PS_MODULE_DIR_.'gallerync/views/img/covers/'.$obj->id.'.'.$obj->cover) / 1000 : false,
        );

I hope this helps.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...