douerqu2319 2014-05-08 15:18
浏览 46
已采纳

文件上传在自定义管理模块的Magento中不起作用

I created a custom admin module in magento. The module has a form which on submitting posts to a controller which handles the file upload.

I am getting the following error on submitting the form:

a:5:{i:0;s:22:"File was not uploaded.";i:1;s:1030:"#0 C:\wamp\www\magento-PhpDevGuide-packt\app\code\local\Endosoft\Categoryupdate\controllers\Adminhtml\CategoryupdateController.php(11): Varien_File_Uploader->__construct('uploadcsv')
#1 C:\wamp\www\magento-PhpDevGuide-packt\app\code\core\Mage\Core\Controller\Varien\Action.php(418): Endosoft_Categoryupdate_Adminhtml_CategoryupdateController->formPostAction()
#2 C:\wamp\www\magento-PhpDevGuide-packt\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('formpost')
#3 C:\wamp\www\magento-PhpDevGuide-packt\app\code\core\Mage\Core\Controller\Varien\Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#4 C:\wamp\www\magento-PhpDevGuide-packt\app\code\core\Mage\Core\Model\App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#5 C:\wamp\www\magento-PhpDevGuide-packt\app\Mage.php(684): Mage_Core_Model_App->run(Array)
#6 C:\wamp\www\magento-PhpDevGuide-packt\index.php(87): Mage::run('', 'store')
#7 {main}";s:3:"url";s:78:"/index.php/admin/categoryupdate/formpost/key/d91e6825136ce2206d7c72bbd1b7af34/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:5:"admin";}

Here is the form:

<?php $url = Mage::helper("adminhtml")->getUrl('adminhtml/categoryupdate/formpost'); ?>
<h4>Upload Your CSV</h4>
<form action="<?php echo $url ?>" method="post" enctype="multipart/form-data">
    <p><input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" /></p>
    <p><input type="file" name="csvupload" /></p>
    <p><input type="submit" name="submit" value="Submit" /></p>
</form>

Here is the controller method:

public function formPostAction() {
  $uploader = new Varien_File_Uploader('uploadcsv');
  $uploader->setAllowedExtensions(array('json'));
  $uploader->setAllowRenameFiles(false);
  $uploader->setFilesDispersion(false);
  $path = Mage::getBaseDir('media');
  $fileName = $_FILES['uploadcsv']['name'];
  $uploader->save($path, $fileName);

  $this->loadLayout();
  $this->renderLayout();
}

I could not understand why the file is not uploaded.

Could someone please clarify what is going wrong?

Additional Info:

  • Instead of using magento form container and form i am using my own form by calling a phtml file from the layout..
  • 写回答

1条回答 默认 最新

  • dqde43215 2014-05-09 06:29
    关注

    I see that your file input looks like this:

    <input type="file" name="csvupload" />
    

    Notice the name csvupload.
    But in the formpostAction you are trying to read the uploadcsv field.
    Make sure that what you submit matches what you process.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题