Prestashop 在发送消息时上传文件
Prestashop uploading file while sending message
我正在尝试添加功能以在订单详细信息页面中附加文件。有一个消息发送表单,我正在尝试在那里实现文件上传。
我已将此添加到订单中-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>
和 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);
}
...
}
}
我从 ContactController.php 复制了它,效果很好,但在这里却不行。有人知道我做错了什么吗?
所以我终于找到了制作方法。我需要编辑 history.js
data: new FormData(this),
然后上传文件。否则 $_FILES[] 被处理为空。
现在可以正常使用了。
我正在尝试添加功能以在订单详细信息页面中附加文件。有一个消息发送表单,我正在尝试在那里实现文件上传。
我已将此添加到订单中-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>
和 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);
}
...
}
}
我从 ContactController.php 复制了它,效果很好,但在这里却不行。有人知道我做错了什么吗?
所以我终于找到了制作方法。我需要编辑 history.js
data: new FormData(this),
然后上传文件。否则 $_FILES[] 被处理为空。
现在可以正常使用了。