prestashop文件上传将无法正常工作

时间:2016-08-17 13:04:40

标签: php prestashop

我正在尝试在订单详情页面中实现文件上传。

创建表单

<form action="" method="post" id="uploadForm" enctype="multipart/form-data">
  <label for="fileUpload">{l s='File to upload:'}</label>
  <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
  <input type="file" name="fileUpload" id="fileUpload" />

<div class="submit">
    <input type="hidden" name="id_order" value="{$order->id|intval}" />
    <input type="submit" class="unvisible" name="submitMessage" value="{l s='Send'}"/>
    <button type="submit" name="submitMessage" class="button btn btn-default button-medium"><span>{l s='Send'}<i class="icon-chevron-right right"></i></span></button>
</div>
</form>

并将其添加到OrderDetailController.php

if (Tools::isSubmit('submitMessage')) {
   $idOrder = (int)Tools::getValue('id_order');
   $msgText = Tools::getValue('msgText');

   if (isset($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['tmp_name']))
   {
     $this->errors[] = Tools::displayError('Works');
   }
   ...

现在,当我提交表单时 - 它会保存消息并完全忽略文件。

有谁知道为什么?

2 个答案:

答案 0 :(得分:1)

解决了自己。已回答here

ajax问题没有发送$ _FILES []数据

答案 1 :(得分:0)

我假设您将其放入默认模板的order-detail.tpl

您将文件输入放在一个单独的表单中,因为它没有提交按钮,所以没有做任何事情。该页面上的评论表格完全不同,这就是您的输入被忽略的原因。

您要做的是将没有<form>标记的html代码放入提交邮件的正确表单中。表单位于order-detail.tpl的底部。

<form action="{$link->getPageLink('order-detail', true)|escape:'html':'UTF-8'}" method="post" class="std" id="sendOrderMessage">
    <h3 class="page-heading bottom-indent">{l s='Add a message'}</h3>
    <p>{l s='If you would like to add a comment about your order, please write it in the field below.'}</p>
    <p class="form-group">
        <label for="id_product">{l s='Product'}</label>
        <select name="id_product" class="form-control">
            <option value="0">{l s='-- Choose --'}</option>
            {foreach from=$products item=product name=products}
                <option value="{$product.product_id}">{$product.product_name}</option>
            {/foreach}
        </select>
    </p>
    <p class="form-group">
        <textarea class="form-control" cols="67" rows="3" name="msgText"></textarea>
    </p>

    <!-- Your html snippet -->
    <p class="form-group">
        <label for="fileUpload">{l s='File to upload:'}</label>
        <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
        <input type="file" name="fileUpload" id="fileUpload" />
    </p>

    <div class="submit">
        <input type="hidden" name="id_order" value="{$order->id|intval}" />
        <input type="submit" class="unvisible" name="submitMessage" value="{l s='Send'}"/>
        <button type="submit" name="submitMessage" class="button btn btn-default button-medium"><span>{l s='Send'}<i class="icon-chevron-right right"></i></span></button>
    </div>
</form>