dataset-file-chek/dataset-files.php

43 lines
1.1 KiB
PHP

<?php
$link = pg_connect("dbname=metadata user=gis password=gispassword host=210.77.68.241");
$host='ftp2.westgis.ac.cn';
//接收uuid
if($argc==2)
{
$uuid = $argv[1];
} else {
$uuid = @$_GET['uuid'];
}
if (""===trim($uuid)) die('Please offer an UUID!');
$sql="select path from dataset where uuid='".$uuid."'";
$result=pg_query($link,$sql);
$row = pg_fetch_row($result);
$content=$row[0]."\n";
$sql="select filename,filesize from datafile where dsid in (select id from dataset where uuid='".$uuid."' and host='".$host."') order by filename";
$result = pg_query($link, $sql);
$numrows = pg_num_rows($result);
for($ri = 0; $ri < $numrows; $ri++)
{
$row = pg_fetch_array($result, $ri);
$content.="./".rtrim($row['filename'],'/')." ";
$content.=$row['filesize']."\n";
}
$filename=$uuid.'-db.txt';
if (!empty($content))
if (!file_put_contents($filename, $content, LOCK_EX))
{
sleep(1);
if (!file_put_contents($filename, $content, LOCK_EX))
{
sleep(1);
if (!file_put_contents($filename, $content, LOCK_EX))
die("error");
}
}
pg_free_result($result);
pg_close($link);