Zend-如何读取上传文件的内容

时间:2016-06-30 22:13:15

标签: php file zend-framework zend-form

我正在上传文件,现在我想读取该文件的内容。但我得到了

array(0) {
}

我在这段代码中做错了什么?

if ($request->isPost()) {
            try {
                $adapter = new Zend_File_Transfer_Adapter_Http();
                $adapter->addValidator('Count', false, array('min' => 1, 'max' => 3))
                        ->addValidator('Size', false, array('max' => 10000))
                        ->addValidator('Extension', false, array('extension' => 'csv', 'case' => true));

                $adapter->setDestination(APPLICATION_PATH ."/../public/tmp/upload");

                $files = $adapter->getFileInfo();
                echo "<pre>";
                //print_r($files);

                foreach($files as $fieldname    =>  $fileinfo) {
                    if (($adapter->isUploaded($fileinfo['name'])) && ($adapter->isValid($fileinfo['name']))){
                        echo $path   =   $fileinfo['destination'].'/'.$fileinfo['name'];
                        chmod($path, 0777);
                        var_dump($adapter->receive($path));

                    }
                }

                var_dump($adapter->getMessages());
            } catch (Exception $ex) {
                echo "Exception!\n";
                echo $ex->getMessage();
            }
        }

1 个答案:

答案 0 :(得分:1)

https://framework.zend.com/manual/1.12/en/zend.file.transfer.introduction.html中使用示例#3,它表示您可以使用getfileName()方法,然后在文件上执行file_get_contents()。

 $filename = array_pop($adapter->getFileName());
 $file_contents = file_get_contents($filename);