Prestashop uploading file while sending message

天涯浪子 提交于 2019-12-12 18:09:44

问题


I am trying to add function to attach file in order details page. There is an message sending form and i am trying to implement file upload in there.

I have added this to order-detail.tpl

<div class="form-group">
    <input type="file" name="fileUpload" id="msgfile" class="inputfile" />
    <label for="msgfile"><i class="icon-cloud-upload"></i> {l s='Prisegti failą'}</label>
    <p id="nbchars"></p>
</div>

and values to OrderDetailController.php

if (Tools::isSubmit('submitMessage')) {
    $extension = array('.txt', '.rtf', '.doc', '.docx', '.pdf', '.zip', '.png', '.jpeg', '.gif', '.jpg');
    $file_attachment = Tools::fileAttachment('fileUpload');
  if (!count($this->errors)) {
  ...
    if (isset($file_attachment['rename']) && !empty($file_attachment['rename']) && rename($file_attachment['tmp_name'], _PS_UPLOAD_DIR_.basename($file_attachment['rename']))) {
        $cm->file_name = $file_attachment['rename'];
        @chmod(_PS_UPLOAD_DIR_.basename($file_attachment['rename']), 0664);
    }
  ...
  }
}

I copied it from ContactController.php which works perfectly, however in here it does not. Anyone have idea what am i doing wrong?


回答1:


SO i eventually found how to make it. I needed to edit history.js

data: new FormData(this),

Then it uploads files. Otherwise $_FILES[] are processed empty.

Now it works fine.



来源:https://stackoverflow.com/questions/38976814/prestashop-uploading-file-while-sending-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!