我在magento中创建了一个自定义管理模块。该模块有一个表单,用于向处理文件上载的控制器提交帖子。
我在提交表单时遇到以下错误:
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";}
以下是表格:
<?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>
这是控制器方法:
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();
}
我无法理解为什么文件没有上传。
有人可以澄清出了什么问题吗?
其他信息:
答案 0 :(得分:1)
我看到你的文件输入如下:
<input type="file" name="csvupload" />
注意名称csvupload
但是在formpostAction
您尝试阅读uploadcsv
字段
确保您提交的内容与您处理的内容相符。