添加文件列表导入功能

This commit is contained in:
wlx 2012-11-17 03:22:50 +00:00
parent 60cd3305e1
commit 2257522aed
1 changed files with 38 additions and 0 deletions

View File

@ -1,4 +1,5 @@
<?php
require_once('mydir.php');
$link = pg_connect("dbname=metadata user=gis password=gispassword host=210.77.68.241");
if (!$link)
{
@ -16,6 +17,7 @@
die("error! You are not permitted to visit this page.".$onlineip);
//文件生成
$uuid=$_GET['uuid'];
$filelist=$_GET['filelist'];
if(empty($uuid) || !preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
die("uuid error! Error in parameter.".$uuid);
@ -26,6 +28,42 @@
$old=umask(0);
@mkdir($homedir,0777);
umask($old);
if ($filelist)
{
//是否应当移除FTP信息即用户提交后不再有权限更新
//todo...
//delete dataset & datafile records
$sql="delete from dataset where uuid='$uuid'";
pg_execute($link,$sql);
$sql = "INSERT INTO dataset (uuid,path) VALUES ('$uuid','$homedir') RETURNING id";
$result=pg_query($link,$sql);
$row=pg_fetch_assoc($result);
$dsid=$row['id'];
$dir = new mydir();
$files=$dir->recursive($homedir);
foreach ($files as $k=>$v)
{
//$pathinfo = pathinfo($path.$v);
$filename = mb_substr($v,mb_strlen($homedir)+1);
$filesize = filesize($v);
$isdir=is_dir($v)?1:0;
$depth=substr_count($filename,"/")+1;
if (substr($filename,-1,1)=='/') $depth--;
//$this->chmodr($path.$v,0444);
$sql = "INSERT INTO datafile (dsid,filename,filesize,isdir,depth) VALUES (?,?,?,?,?)";
$sth = $this->db->prepare($sql);
$rs = $sth->execute(array($dsid,$filename,$filesize,$isdir,$depth));
if(!$rs)
{
$messages[] = "数据文件".$filename.'写入失败';
}
}
}
pg_free_result($result);
pg_close($link);