html代码
<pre class="php" name="code"><fieldset>
<legend>批量导入学生照片</legend>
<form enctype="multipart/form-data" action="/Import/importstuimg" method="post">
导入照片压缩包文件:<input value="导入文件" type="file" name="file1"/>
上传文件:<input type="submit" class="buttons" value="上传文件" />
</form>
</fieldset>
php代码
public function importstuimgAction()
{
$dir=DOCS_PATH;//指定文件存储位置
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination ($dir);//设置路径
$filename='stuimg'.'.'.'zip';//重命名
$adapter->addFilter('Rename', array('target' => $filename, 'overwrite' => true));//运行重命名
$adapter->addValidator( 'Extension', false, 'zip' )->addValidator( 'Size', false, 1048576*5)->addValidator( 'Count', false, 1 );//传到当前文件夹下设置文件
if($adapter->receive()){
$zip = new ZipArchive;
$res = $zip->open(DOCS_PATH.'/stuimg.zip');
if ($res === TRUE) {
//解压缩到test目录
$zip->extractTo(PUBLIC_PATH.'/stuimg');//PUBLIC_PATH指定的位置
$zip->close();
} else {
echo 'failed, code:' . $res;
}
}
//删除暂时文件
unlink(DOCS_PATH.'/stuimg.zip');
//跳回导入页面
$this->_forward("import","import");
}