...

View Full Version : creating backlogs of files depending on the date



phpnoobtv
01-17-2012, 09:51 PM
I'm looking for directions on a problem with creating some files.

Here's the gist of what I am trying to do.

Look into a file and check if file exists. If it doesn't exist create the file.

Essentially I am trying to create a file for every week for the past 2 years.

each time I create the file its suppose to have the date of each week appended to it

ie) file naming structure:
"randomtext_". $startweek . '_' . $endweek.'.php';


<?php

define("SRV_RT",realpath(dirname(__FILE__).'/..'));

$end_curr_week = mktime(0,0,0,date("m"), date("d") + (-1 * date("w")+6), date("Y")); // Current week (saturday)
$first_week = mktime(0,0,0,1,1,2010);
$diff = $end_curr_week - $first_week; // figure out how many weeks there are from current week to Jan 1, 2010.

$numofweek=($diff / (7*24*60*60));
echo $numofweek; // checking my number

/*$filepath = SRV_RT. "/randomtext_". $startweek . '_' . $endweek.'.php';
if (file_exists($filepath)) { exit;}
else{$Handle = fopen($filepath, "w+") or die("can't open file"); } */

$num = 0;
while ($num <= $numofweek){
$num++;
$list= $num * 7;
echo $list. '<br>';
}

$period_start = mktime(0,0,0,date("m"), date("d") + ((-1 * date("w"))-$list), date("Y")); // start of current week

$period_end = mktime(0,0,0,date("m"), date("d") + ((-1 * date("w")+6)-$list), date("Y"));

$end_week = date('Ymd', $period_end);
$start_week = date('Ymd', $period_start);

?>

That's just some things I been thinking about. I thought if I figure out how many numbers of week there are in the past years I can use that to change my $period_start and $period_end.


$period_start = mktime(0,0,0,date("m"), date("d") + ((-1 * date("w"))-$list), date("Y")); // start of week

$period_end = mktime(0,0,0,date("m"), date("d") + ((-1 * date("w")+6)-$list), date("Y")); End of week

Only problem is I don't know how to get the period start and period end to keep looping until Jan 01, 2010.

Am I doing this the wrong way? I really need $period_start and $period_end to change for every week for the past to 2 years.


I figured it out nvm. Put the date into an array, so simple.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum