1

If creating the addon.xml file for cs-cart module and specifying an option with type=file like that

<?xml version="1.0"?>
<addon scheme="3.0">
    <id>my_addon</id>
    <version>1.0</version>
    <priority>4000</priority>
    <status>active</status>
    <auto_install>ULTIMATE,MULTIVENDOR</auto_install>
    <default_language>en</default_language>

    <dependencies/>
    <settings edition_type="ROOT,ULT:VENDOR">
        <sections>
            <section id="general">
                <items>
                    <item id="attach_file">
                        <type>file</type>
                    </item>
                </items>
            </section>
        </sections>
    </settings>
</addon>

Everything works perfectly on client side: file manager opens by clicking on "Browse..." button, and user can upload and select the file. But when the file in file manager is selected, only it's end filename is pasted into the module settings form field, so, it doesn't store the uploaded file location/path. Only it's filename. I have tried using

Registry::get('config.dir.files').Registry::get('addons.my_addon.attach_file');

To get the complete uploaded file path, but It doesn't work properly. It returns something like /path/to/site/root/var/files/my-file.pdf instead of the real /path/to/site/root/var/files/1/my-file.pdf (there is an extra 1 directory before the filename and I do not know how to represent it). If adding that extra 1 manually, then it may not work on different CS-Cart configurations.

So, how can I get the complete uploaded file path from the file manager in module settings popup from administration panel?

impulsgraw
  • 887
  • 3
  • 13
  • 34

1 Answers1

1

The fn_get_files_dir_path() global function will return the context specific (store specific) file path.

Eg. in your case it will return: /path/to/site/root/var/files/1/. Then you can grab the filename from the add-on settings: Registry::get('addons.my_changes.file') and you are good to go.

However you can link public file to an add-on setting, so it can be 2 scenarios:

A: The file's path is: fn_get_files_dir_path() . Registry::get('addons.my_changes.file')

or

B: The file's path is: fn_get_public_files_path() . Registry::get('addons.my_changes.file')

Before you use the file, you should check which path is valid.

ISTI
  • 201
  • 1
  • 4