79 lines
2.7 KiB
PHP
79 lines
2.7 KiB
PHP
<?php
|
|
class Downloadphoto extends MY_Controller
|
|
{
|
|
var $base_dir = "/home/one/project/one/one-media/one-photo/patient/";
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
$this->load->helper(array('form', 'url'));
|
|
|
|
}
|
|
|
|
function start(){
|
|
$companynumber = $this->input->get("companynumber");
|
|
$start_date = $this->input->get("startdate");
|
|
$end_date = $this->input->get("enddate");
|
|
$sql = "SELECT m_patient.*, T_OrderHeaderLabNumber,M_CompanyNumber FROM t_orderheader
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
|
|
WHERE `M_PatientPhoto` IS NOT NULL AND M_CompanyNumber = '{$companynumber}' AND ( DATE(T_OrderHeaderDate) >= '{$start_date}' AND DATE(T_OrderHeaderDate) <= '{$end_date}' ) AND T_OrderHeaderIsActive = 'Y'";
|
|
//echo $sql;
|
|
$rst = $this->db_onedev->query($sql)->result_array();
|
|
if($rst){
|
|
$companynumber = $rst[0]['M_CompanyNumber'];
|
|
$newdir = $this->base_dir."xphoto".$companynumber;
|
|
//echo $newdir;
|
|
if (!file_exists($newdir)) {
|
|
//echo $newdir;
|
|
mkdir($newdir, 0777, true);
|
|
}
|
|
else{
|
|
unlink($newdir);
|
|
mkdir($newdir, 0777, true);
|
|
}
|
|
foreach($rst as $k => $v){
|
|
$photo_explode = explode('/',$v['M_PatientPhoto']);
|
|
copy('/home/one/project/one/'.$v['M_PatientPhoto'], $newdir.'/'.$photo_explode[5]);
|
|
}
|
|
$this->download($companynumber);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function small(){
|
|
|
|
$y = $this->input->get("y");
|
|
$pid = $this->input->get("pid");
|
|
$foto_file = $this->base_dir . "$y" . "/" . $pid . "_thumb.jpg";
|
|
header('Content-type: image/jpg');
|
|
|
|
echo file_get_contents($foto_file);
|
|
}
|
|
|
|
function download($companynumber) {
|
|
$filenow = $this->base_dir."xphoto".$companynumber;
|
|
//$filenow = "/home/one/project/one/one-media/one-photo/patient/xcoba";
|
|
|
|
$temp_file = tempnam(sys_get_temp_dir(), 'photo-'.$companynumber.'-') . ".tar.gz";
|
|
if ( file_exists($temp_file) ) unlink($temp_file);
|
|
$cmd = "tar -C $filenow -cvf $temp_file ./";
|
|
exec($cmd);
|
|
if (file_exists($temp_file)) {
|
|
header('Content-Description: File Transfer');
|
|
header('Content-Type: application/octet-stream');
|
|
header('Content-Disposition: attachment; filename="'.basename($temp_file).'"');
|
|
header('Expires: 0');
|
|
header('Cache-Control: must-revalidate');
|
|
header('Pragma: public');
|
|
header('Content-Length: ' . filesize($temp_file));
|
|
readfile($temp_file);
|
|
unlink($temp_file);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|