|
Server : Apache/2.2.2 (Fedora) System : Linux App1.pathumtani.go.th 2.6.20-1.2320.fc5smp #1 SMP Tue Jun 12 19:40:16 EDT 2007 i686 User : apache ( 48) PHP Version : 5.2.9 Disable Function : NONE Directory : /var/www/html/pathumthani_eoffice/application/agenda/ |
Upload File : |
<?php
header('Content-Type: text/plain; charset=windows-874');
//=========================================
// Select attach files where status id_attach_file = $sub_id
// @author Kridsada Satakarn
// @date 2009/06/20
// @return a array of list attach files where status id_attach_file = $sub_id
//=========================================
function selectAttachFiles($sub_id)
{
$arr = array();
$sql = "SELECT
tbl_attach_file.attach_file,
tbl_attach_file.run_id ,
tbl_attach_file.comment
FROM
tbl_attach_file
WHERE
tbl_attach_file.id_attach_file = '$sub_id' order by run_id ASC";
$query = mysql_query($sql);
while($rs = mysql_fetch_assoc($query))
{
$arr[$rs[run_id]] = $rs[attach_file];
}
return $arr;
} ########## END function selectAttachFiles($sub_id)
function showListFile($id)
{
$listFiles = selectAttachFiles($id);
if(count($listFiles) > 0)
{
foreach($listFiles as $key => $value)
{
echo "<a href='attach_file/".$id. "/". $value."' target='_blank' >".$value."</a>". "<a href='#' onclick=\"delFile('DEL', '".$value ."', ' ', '" .$key ."', '" .$id ."')\"><img src='images/delete.gif' width='15' height='15' alt='źä¿Åì' border='0'></a><br>";
}
}else
{
echo " ";
}
} ######## END function showListFile($id)
//===============================================
include("../../config/config.inc.php");
$action=$_GET['act'];
$file_path=$_GET['file'];
$id_sub=$_GET['id_sub'];
$id_type = $_GET['id_type'];
$arr_file = explode("/", $file_path);
if(count($arr_file) < 2)
{
$arr_file = explode("\\", $file_path);
}
//$filename = basename($file_path);
$filename = $arr_file[count($arr_file)-1];
# $path_add = "/attach_file/temp/";
# $path_edit = "attach_file/";
$path_add = "/attach_file/temp/";
$path_edit = "attach_file/";
if($action == "ADD")
{
$time = time();
$complete = copy($file_path , $path_add.$time.$filename);
#echo " $path_add --- $time ---- $filename ";
if($complete)
{
echo "$time,$filename";
}
}else if($action == "EDIT")
{
if(!file_exists("$path_edit$id_sub"))
{
mkdir("$path_edit$id_sub");
}
$up_file = @copy("$file_path", "$path_edit$id_sub/$filename");
if($up_file)
{
$sql = "INSERT INTO tbl_attach_file(id_attach_file, id_type,comment, attach_file, status_file) VALUES ($id_sub, $id_type, $filename, '$filename', 'Y')";
$rss = mysql_db_query($dbname,$sql);
$last = mysql_insert_id();
}
if($up_file && $rss)
{
echo "$last,$filename";
}
}else if($action == "DEL_TEMP")
{
$timestamp = $_GET[timestamp];
$deleted = unlink("$path_add$timestamp$filename");
if($deleted)
{
echo "$filename";
}
}else if($action == "DEL")
{
$rid = $_GET[rid];
$sql = "DELETE FROM tbl_attach_file WHERE run_id = $rid";
$rss = mysql_db_query($dbname,$sql);
$deleted = unlink("$path_edit$id_sub/$filename");
if($deleted)
{
echo showListFile($id_sub);
}
}else
{
echo "";
}
?>