我正在上传一个文件,现在我想读取该文件的内容。但是我得到
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();
}
}
使用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);