简体   繁体   中英

How to receive a File in Zend Framework 2

I am using ZF2.

I am sending a file via a HTML form not generated by Zend/Form . Now I am trying to get that file as i would normally do with $_FILES . I tried the below PHP code but all I get in the print_r is Array ( [upload] => bnk.csv )

How do I get all the metadata such as temp_dir of that file???.... I am new to Zend so dont know if I am forced to create the form with Zend/Form which seems silly since I only have a file upload field thats a lot easier to manage directly from the view.

$request = $this->getRequest();
            if($request->isPost()){
                $post= array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
                print_r($post);
            }


<form id="upload" method="post" action="bnk/upload/csv" enctype="multipart/form-data">
        <label for="upload">Upload CSV File</label>
        <input type="file" name="upload" />
        <input type="submit"/>
</form>
  /* upload */
    $upload = new Zend_File_Transfer_Adapter_Http();
    $upload->setDestination("folder for upload");

    $upload->addValidator('Size',false, 1024 * 1024 * 5 ); //size limit
    $upload->addValidator('Extension',false,'zip,rar'); //extension limit

    $files = $upload->getFileInfo();

    foreach($files as $file=>$info){
        //if file is valid
        if($upload->isValid($file)){
            //confirm to upload
            $upload->receive($file);
        }
    }

I use Zend_File_Transfer_Adapter_Http for uploading

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM