簡體   English   中英

如何在Magento中更改上傳的文件名?

[英]How to change uploaded file name in Magento?

我正在使用system.xml配置通過后端上傳文件。 它運作完美。

但是我需要將上傳的圖片的名稱更改為當前的store id 我怎樣才能? 現在,它以其原始名稱上傳。

我的system.xml

<?xml version="1.0"?>
<config>
  <tabs>
    <restaurant translate="label" module="restaurant">
        <label>Upload Logo</label>
        <sort_order>999999</sort_order>
    </restaurant>
  </tabs>
  <sections>
    <restaurant_options translate="label">
      <label>Upload Logo</label>
      <tab>general</tab>
      <frontend_type>text</frontend_type>
      <sort_order>1000</sort_order>
      <show_in_default>1</show_in_default>
      <show_in_website>1</show_in_website>
      <show_in_store>1</show_in_store>
       <groups>
            <SAMPLE translate="label">
              <label>Upload Your Store's Logo</label>
              <frontend_type>text</frontend_type>
              <sort_order>100</sort_order>
              <show_in_default>1</show_in_default>
              <show_in_website>1</show_in_website>
              <show_in_store>1</show_in_store>
              <fields>
                    <ENABLED translate="label comment">
                        <label>Logo</label>
                        <comment>file types: jpeg, gif, png.</comment>
                        <frontend_type>image</frontend_type>
                        <backend_model>adminhtml/system_config_backend_image</backend_model>
                        <upload_dir config="system/filesystem/media" scope_info="1">theme</upload_dir>
                        <base_url type="media" scope_info="1">theme</base_url>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </ENABLED>
            </fields>
            </SAMPLE>
      </groups>
    </restaurant_options>
  </sections>
</config>

請如果有任何解決方案。

我所知道的。 首先將記錄插入數據庫,並使用插入ID

$ uniqID = mysql_insert_id();

然后

move_uploaded_file($ _ FILES ['userFile'] ['tmp_name'],$ path_to_upload。$ uniqID);

當心:別忘了獲取文件擴展名。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM