2012-11-16 15:46:33 +00:00
|
|
|
|
<?php
|
2012-11-17 03:22:50 +00:00
|
|
|
|
require_once('mydir.php');
|
2012-11-16 15:46:33 +00:00
|
|
|
|
$link = pg_connect("dbname=metadata user=gis password=gispassword host=210.77.68.241");
|
|
|
|
|
if (!$link)
|
|
|
|
|
{
|
|
|
|
|
die("Error in connection: " . pg_last_error());
|
|
|
|
|
}
|
|
|
|
|
//安全检查:只接受来自westdc.westgis.ac.cn的访问
|
|
|
|
|
if(@$_SERVER['HTTP_CLIENT_IP']){
|
|
|
|
|
$onlineip=$_SERVER['HTTP_CLIENT_IP'];
|
|
|
|
|
}elseif(@$_SERVER['HTTP_X_FORWARDED_FOR']){
|
|
|
|
|
$onlineip=$_SERVER['HTTP_X_FORWARDED_FOR'];
|
|
|
|
|
}else{
|
|
|
|
|
$onlineip=$_SERVER['REMOTE_ADDR'];
|
|
|
|
|
}
|
2012-12-03 04:19:41 +00:00
|
|
|
|
if ($onlineip!='210.77.68.241' && $onlineip!='210.77.68.215' && $onlineip!='2002:d24d:448d:4:214:22ff:fe08:d277')
|
2012-11-16 15:46:33 +00:00
|
|
|
|
die("error! You are not permitted to visit this page.".$onlineip);
|
|
|
|
|
//文件生成
|
|
|
|
|
$uuid=$_GET['uuid'];
|
2012-11-17 03:22:50 +00:00
|
|
|
|
$filelist=$_GET['filelist'];
|
2012-11-16 15:46:33 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$homedir='/disk1/WestDC/upload/'.$uuid;
|
|
|
|
|
|
|
|
|
|
$old=umask(0);
|
|
|
|
|
@mkdir($homedir,0777);
|
|
|
|
|
umask($old);
|
2012-11-17 03:22:50 +00:00
|
|
|
|
if ($filelist)
|
|
|
|
|
{
|
|
|
|
|
//是否应当移除FTP信息?即用户提交后不再有权限更新
|
|
|
|
|
//todo...
|
|
|
|
|
|
|
|
|
|
//delete dataset & datafile records
|
|
|
|
|
$sql="delete from dataset where uuid='$uuid'";
|
2012-11-17 08:54:43 +00:00
|
|
|
|
pg_query($link,$sql);
|
2012-11-17 03:22:50 +00:00
|
|
|
|
|
|
|
|
|
$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);
|
2012-11-17 08:54:43 +00:00
|
|
|
|
$sql = "INSERT INTO datafile (dsid,filename,filesize,isdir,depth) VALUES ('$dsid','$filename','$filesize','$isdir','$depth')";
|
|
|
|
|
$rs = pg_query($link,$sql);
|
2012-11-17 03:22:50 +00:00
|
|
|
|
if(!$rs)
|
|
|
|
|
{
|
|
|
|
|
$messages[] = "数据文件".$filename.'写入失败';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-16 15:46:33 +00:00
|
|
|
|
|
|
|
|
|
pg_free_result($result);
|
|
|
|
|
pg_close($link);
|
|
|
|
|
?>
|