common.php
function nameTodata($value='')
{
$arr1=explode("/",$value);
$filename=end($arr1);
$arr2=explode(".",$filename);
$name=$arr2[0];
$arr3=explode("_",$name);
if(count($arr3)==2){
return [$arr3[0],$arr3[1]];
}else{
return false;
}
}
function ArrToPath($basePath,$arr)
{
$list=[];
foreach ($arr as $k => $v) {
if(is_array($v)){
$list=$list+ArrToPath($basePath. DS .$k,$v);
}else{
$list[]=$basePath. DS .$v;
}
}
return $list;
}
function read_all_dir($dir)
{
$arr = array();
$hander = scandir($dir); //列出文件下的目录
foreach ($hander as $v) { //遍历文件夹下所有文文件
if (is_dir($dir . DS . $v) && $v != "." && $v != "..") { //判断文件夹下是否还有文件夹需要遍历
$arr[$v] = read_all_dir($dir . DS . $v); //递归调用
}else{
if($v != "." && $v != ".."){ //排除 "." " .."
$arr[]=$v; //文件存入
}
}
}
return $arr;
}
方法
/**
* 图文
*
* @return string
* @throws \think\Exception
*/
public function tuwen()
{
if (false === $this->request->isPost()) {
$clist=db("cms_channel")->where("model_id","in",[12,13])->where("type","list")->select();
$this->view->assign("clist", $clist);
return $this->view->fetch();
}
$cid=$this->request->param("cid");
$zippath=$this->request->param("zip");
$channelRow=db("cms_channel")->where("id",$cid)->find();
if(empty($channelRow)){
$this->error("未找到指定栏目");
}
if(!in_array($channelRow["model_id"],[12,13])){
$this->error("该栏目不支持导入");
}
$unpathtmp=explode(".",$zippath);
unset($unpathtmp[count($unpathtmp)-1]);
$unpathtmp=implode("", $unpathtmp);
$file=ROOT_PATH."public".$zippath;
$unpath=ROOT_PATH."public".$unpathtmp;
// dump($file);
// dump($unpath);
// dump($unpathtmp);
// exit;
//解压
$toDirPath=\fast\ZipUtil::extract($file, $unpath);
//dump($toDirPath);
//获取目录文件列表
$listarr=read_all_dir($toDirPath);
$list=ArrToPath($unpathtmp,$listarr);
dump($list);
// $insert=[];
// foreach ($names as $k => $v) {
// $insert[$k]["title"]=$v;
// $insert[$k]["nian"]=$year;
// $insert[$k]["channel_id"]=$channel_id;
// }
// try {
// $this->model->allowField(true)->saveAll($insert);
// } catch (PDOException $exception) {
// $msg = $exception->getMessage();
// if (preg_match("/.+Integrity constraint violation: 1062 Duplicate entry '(.+)' for key '(.+)'/is", $msg, $matches)) {
// $msg = "导入失败,包含【{$matches[1]}】的记录已存在";
// };
// $this->error($msg);
// } catch (Exception $e) {
// $this->error($e->getMessage());
// }
// $insert=[];
// foreach ($names as $k => $v) {
// $insert[$k]["title"]=$v;
// $insert[$k]["nian"]=$year;
// $insert[$k]["channel_id"]=$channel_id;
// }
// try {
// $this->model->allowField(true)->saveAll($insert);
// } catch (PDOException $exception) {
// $msg = $exception->getMessage();
// if (preg_match("/.+Integrity constraint violation: 1062 Duplicate entry '(.+)' for key '(.+)'/is", $msg, $matches)) {
// $msg = "导入失败,包含【{$matches[1]}】的记录已存在";
// };
// $this->error($msg);
// } catch (Exception $e) {
// $this->error($e->getMessage());
// }
// $this->success("导入成功");
$this->success();
}
js和htmlhttp://blog.dj5.cn/uploads/20230527/89803f25e866f8da0616600e4b3cb6f3.rar
完整
http://blog.dj5.cn/uploads/20230527/7bf2f1fcabf4373fc858f9b173d8e278.rar
发表评论 取消回复