I have a form:

<form class="customDocs" method="post" action="<?php echo $this->getUrl('customdocuments/index/send') ?>">
   <h2>Upload Seller's Permit Here:</h2>
   <input type="file" name="sellerPermit" id="sellerPermit">
   <input class="submitBtn" type="submit" value="Upload Documents" name="submit">

Which is submitted to my controller:

class Sean_CustomDocuments_IndexController extends Mage_Core_Controller_Front_Action{
    public function indexAction(){
    public function sendAction(){ //handles the form submit
        $post = Mage::app()->getRequest()->getParams();
        $info = pathinfo('/media/custom_documents/seller_permits/' . $post['seller_permit']);
        $ext = $info['extension'];
        $filename = $post['seller_permit'] . $ext;
        $target = '/media/custom_documents/seller_permits' . $filename;
        move_uploaded_file($post['sellerPermit'], $target);

        Mage::getSingleton('core/session')->addSuccess($this->__('Your Documents have been updated!'));//add success message.

I want to save their file into this directory: /media/custom_documents/seller_permits/ Is there something I'm missing or is this not possible?


Along with @ForgeOnline Answer, you need to do following changes.

You are collecting file input in wrong way in your controller. Currently what you are doing is this:

$post = Mage::app()->getRequest()->getParams();
$info = pathinfo('/media/custom_documents/seller_permits/' . $post['seller_permit']);

This is wrong because. $post variable only holds $_GET and $_POST data. It does not hold $_FILES data which is where file data from forms are kept.

So you need following code:

if(isset($_FILES['sellerPermit']['name']) && $_FILES['sellerPermit']['name'] != '') {
    try {   
        $uploader = new Varien_File_Uploader('sellerPermit');
        // Any extention would work

        $path = Mage::getBaseDir('media').DS.'custom_documents'.DS.'seller_permits';
        $uploader->save($path, $_FILES['sellerPermit']['name'] );
        } catch (Exception $e) {



To change file name, you need to do this:

//here I added new name same as scopeId
$ext     = pathinfo($filename, PATHINFO_EXTENSION);
$newname = 'your_file_new_name' . $ext;
$result  = $uploader->save($path, $newname);

I hope you got the idea.


Your form is missing with attribute enctype="multipart/form-data". ie,

<form class="customDocs" method="post" enctype="multipart/form-data"></form>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.