문제

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..
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top