ahmad19
یک شنبه 24 خرداد 1394, 20:25 عصر
سلام یه برنامه می خوام بنویسم که اولا تایمر داشته باشه و مثلا هر نیم ساعت اجرا بشه
بعد بیاد چک کنه ببینه فایل مورد نظر ما موجوده یا نه
اگه موجود بود پاکش کنه و اگه نبود فایل رو از آدرسی که ما بهش می دیم دانلود کنه و ذخیره کنه
و این دور همینطور ادامه داشته باشه
دوستان لطف می کنن توابع هر مراحله رو بگن
و اینکه این کدها کارم رو راه می ندازه
این برای تایمر
<?php
function countdown()
{
// $start_game_time zaman aghaz bazi
// $countdown zaman mande be aghaz
global $start_game_time,$countdown, $hcount,$mcount,$difference;
$second=1;
$minute=$second*60;
$hour=$minute*60;
$day=$hour*24;
$week=$day*7;
$time=$start_game_time;
$offset=mktime();
$difference=$time-$offset;
$hcount=0;
for($hcount=0; $difference>$hour; $hcount++) {
$difference=($difference-$hour); }
$mcount=0;
for($mcount=0; $difference>$minute;
$mcount++){
$difference=$difference-$minute;}
$countdown=$hcount.':'.$mcount.':'.$difference; //Hour , Min, Sec
}
// example
$start_game_time = (mktime()+200);
countdown();
?>
<script type="text/javascript">
function timer(data, lnk){
dat=document.getElementById(data);
var time=(dat.innerHTML).split(":"); var done=0;
if (time[2]>0) time[2]--;
else{
time[2]=59;
if(time[1]>0) time[1]--;
else{time[1]=59;
if (time[0]>0) time[0]--;
else { clearTimeout(id[data]); window.location.href=lnk; done=1;} }}
if(!done){
dat.innerHTML=time[0]+":"+time[1]+":"+time[2];
id[data]=setTimeout("timer('"+data+"', '"+lnk+"')", 1000); }}
</script>
<span id="time"><?php echo $countdown; ?></span>
<script type="text/javascript">var id=new Array(50); timer('time','end.php');</script>
اینم دانلود فایل
$strDownload = $strDownloadFolder.$arrCheck['file'];
$strFile = file_get_contents($strDownload);
$filename = basename($strDownload);
$mime = 'application/x-download'; // or application/pdf
if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE)
{
header('Content-Type: "'.$mime.'"');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Transfer-Encoding: binary");
header('Pragma: public');
header("Content-Length: ".strlen($strFile));
}
else
{
header('Content-Type: "'.$mime.'"');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
header("Content-Length: ".strlen($strFile));
}
exit($strFile);
بعد بیاد چک کنه ببینه فایل مورد نظر ما موجوده یا نه
اگه موجود بود پاکش کنه و اگه نبود فایل رو از آدرسی که ما بهش می دیم دانلود کنه و ذخیره کنه
و این دور همینطور ادامه داشته باشه
دوستان لطف می کنن توابع هر مراحله رو بگن
و اینکه این کدها کارم رو راه می ندازه
این برای تایمر
<?php
function countdown()
{
// $start_game_time zaman aghaz bazi
// $countdown zaman mande be aghaz
global $start_game_time,$countdown, $hcount,$mcount,$difference;
$second=1;
$minute=$second*60;
$hour=$minute*60;
$day=$hour*24;
$week=$day*7;
$time=$start_game_time;
$offset=mktime();
$difference=$time-$offset;
$hcount=0;
for($hcount=0; $difference>$hour; $hcount++) {
$difference=($difference-$hour); }
$mcount=0;
for($mcount=0; $difference>$minute;
$mcount++){
$difference=$difference-$minute;}
$countdown=$hcount.':'.$mcount.':'.$difference; //Hour , Min, Sec
}
// example
$start_game_time = (mktime()+200);
countdown();
?>
<script type="text/javascript">
function timer(data, lnk){
dat=document.getElementById(data);
var time=(dat.innerHTML).split(":"); var done=0;
if (time[2]>0) time[2]--;
else{
time[2]=59;
if(time[1]>0) time[1]--;
else{time[1]=59;
if (time[0]>0) time[0]--;
else { clearTimeout(id[data]); window.location.href=lnk; done=1;} }}
if(!done){
dat.innerHTML=time[0]+":"+time[1]+":"+time[2];
id[data]=setTimeout("timer('"+data+"', '"+lnk+"')", 1000); }}
</script>
<span id="time"><?php echo $countdown; ?></span>
<script type="text/javascript">var id=new Array(50); timer('time','end.php');</script>
اینم دانلود فایل
$strDownload = $strDownloadFolder.$arrCheck['file'];
$strFile = file_get_contents($strDownload);
$filename = basename($strDownload);
$mime = 'application/x-download'; // or application/pdf
if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE)
{
header('Content-Type: "'.$mime.'"');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Transfer-Encoding: binary");
header('Pragma: public');
header("Content-Length: ".strlen($strFile));
}
else
{
header('Content-Type: "'.$mime.'"');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
header("Content-Length: ".strlen($strFile));
}
exit($strFile);