0

I'm getting mad at an error, more like the lack of error, that I don't understand. I'm trying to upload a file to a directory via Zend_Framework.

Here's my php:

if (($this->_request->getPost('file_upload', false))) {
             if ($this->view->form->isValid($_POST)) {
                $data = $this->view->form->getValues();
                Zend_Debug::dump($data);
                if (!file_exists(APPLICATION_PATH .  "/../docs_client")) {
                    mkdir(APPLICATION_PATH . "/../docs_client");
                }
                if (!file_exists(APPLICATION_PATH . "/../docs_client/"  . $id . "/" . $data['annonce_id'])) {
                    mkdir(APPLICATION_PATH . "/../docs_client/" . $id . "/" . $data['annonce_id'], 0700, true);
                }
                $dirName = APPLICATION_PATH . "/../docs_client/" . $id . "/" . $data['annonce_id'] . '/';

                $adapter = new Zend_File_Transfer_Adapter_Http();   
                $adapter->setDestination($dirName);
                if ($data['accord'] != NULL) {
                    $accord = $adapter->getFileInfo('accord');
                    Zend_Debug::dump($accord);
                    $accordInfo = $accord['accord'];
                    $name = $accordInfo['name'];
                    $extension = pathinfo($accordInfo['name'], PATHINFO_EXTENSION);
                    $fname = "accord_bailleur_" . $id . "_" . $data['annonce_id'] . '_' . uniqid() . '.' . strtolower($extension);
                    $adapter->addFilter(new Zend_Filter_File_Rename(array(
                            'target' => $fname, 
                            'overwrite' => true
                            )), null, $accord);

                    if (!$adapter->receive($accord)){

                        //die ( print_r ( $adapter->getMessages (), 1 ) );
                    }
                    Zend_Debug::dump($fname);
                    //Zend_Debug::dump($accord);die();
                }

             }
        }

In my zend form, I've set valueDisabled to true. In my html form, I've set the enctype as "multipart/form-data"

When I try to upload my file, the directories are created if they're missing, everything foes like it's supposed to do except that my file doesn't upload. I've nothing in my temp directory or the upload directory I've set. When I try to display the errors I have an empty array.

Here's my debug:

/* POST DATA */
array(4) {
  ["accord"] => string(36) "0b4f7b468ad649ccbe8d2c78d3f50389.pdf"
  ["loyer"] => NULL
  ["justificatif"] => NULL
  ["annonce_id"] => string(3) "337"
}

/* CONTENT OF $accord*/
array(1) {
  ["accord"] => array(11) {
    ["name"] => string(36) "0b4f7b468ad649ccbe8d2c78d3f50389.pdf"
    ["type"] => string(15) "application/pdf"
    ["tmp_name"] => string(27) "C:\Windows\Temp\phpE10B.tmp"
    ["error"] => int(0)
    ["size"] => string(7) "3258008"
    ["options"] => array(4) {
      ["ignoreNoFile"] => bool(false)
      ["useByteString"] => bool(true)
      ["magicFile"] => NULL
      ["detectInfos"] => bool(true)
    }
    ["validated"] => bool(false)
    ["received"] => bool(false)
    ["filtered"] => bool(false)
    ["validators"] => array(1) {
      [0] => string(25) "Zend_Validate_File_Upload"
    }
    ["destination"] => string(86) "C:\Program Files (x86)\Zend\Apache2\htdocs\esubletz1\application/../docs_client/17/337"
  }
}
/* CONTENT OF $fname*/
string(40) "accord_bailleur_17_337_5224634612c1d.pdf"

I have more or less the same code for another file upload and it works fine.

I don't understand why this one doesn't.

2 Answers 2

1

Use this simple and easy example on file upload by rob, it will be very helpful, and will provide you a proper way and approach to upload files in ZF.

http://akrabat.com/zend-framework/simple-zend_form-file-upload-example/

Sign up to request clarification or add additional context in comments.

Comments

0

Well, after all that time the error was just that in

$adapter->addFilter(new Zend_Filter_File_Rename(array(
                            'target' => $fname, 
                            'overwrite' => true
                            )), null, $accord);

                    if (!$adapter->receive($accord)){

                        //die ( print_r ( $adapter->getMessages (), 1 ) );
                    }

$accord isn't supposed to be the array, but the string of the name of that array, in that case "accord". And like every time I find the error just after I post here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.