PHP - List Files Based On Last Modification Time.
Hello Coder Guys,
I need a small help from you. I want to list all files & directories based on last file modification time of server. I want to list new files as first & old files as last. Consider "files" as the directory name which contains all files & directories. Please make the php code to display all files & directories from "files" directory based on last file modification time of server. Thanks IN Advance ! Similar TutorialsI have a table in my database which stores lot of file names & file path. iam currently listing the files on the basis of its uploaded date (stored in databse) but I want to list it on the basis of its file modification time. How i can do it ?? my current sql statement is Code: [Select] $sql = mysql_query("SELECT * FROM `files` WHERE `cid` = '$types' ORDER BY `uploaded` DESC LIMIT $start,$limit"); anyone can help me ?? Basically I have recently been playing around with parsing a csv file. What I am looking to do at this point is simply take the date/timestamp (part of the csv file), which is in the following format:DD/MM HH:MM:SS.100th/s For the sake of argument, lets say I have this in an array string called $csv[0] and the file has several lines that span the course of a couple hours. I wouldn't mind having to use explode() to breakup/remove the date or 100th/s IF that would make things a lot simpler. So where would I start in trying to achieve this?. The result I am looking for will simply return "X Seconds". Storing this in a string variable would be a bonus, as I plan to use this to divide a separate piece of information. Any examples or ideas would be great. Thank you. ps: Here is an example time from the csv file itself: Code: [Select] 11/19 22:23:18.143 Hello I have a simple question about file handling... Is it possible to list all files in directories / subdirectories, and then read ALL files in those dirs, and put the content of their file into an array? Like this: array: [SomePath/test.php] = "All In this php file is being read by a new smart function!"; [SomePath/Weird/hello.txt = "Hello world. This is me and im just trying to get some help!";and so on, until no further files exists in that rootdir. All my attempts went totally crazy and none of them works... therefore i need to ask you for help. Do you have any ideas how to do this? If so, how can I be able to do it? Thanks in Advance, pros Hello everyone, here is my problem. I am working for someone that would like users to be able to create a Trial Account on their website. This trial account is to be used for 24 hours, once the 24 hours is completed they can no longer login/use that account. Everything about the Trial Account is completed, other then the account timer. I am at a loss on how to get this part done. I was thinking that I would use the MySQL commands, GETDATE() and DATEADD(), to get the date and time that the account was created and using the DATEADD() command I would add 24 hours to the GETDATE() value. Then if the user logs into at a date past the DATEADD() value the Users Account type is switched to 3(This means that the account has been disabled) and then is directed to the Logout page, which then redirects him back to the homepage. After this point, the user can no longer login due to the code preventing any user with an account type of 3 to login. The problem is that I am unaware how to incorporate the GETDATE() and DATEADD() functions into my PHP code. Would anyone be able to explain how I can get this done, or suggest a better method of inputting a starting time and ending time for the account? Thank You for any/all help. Hi peps, I am trying to write a script that allows for events to be executed at any given time that user gives it like if the user wants it at 2 am the event will execute at that given time i read some answer they say use cron but im using windows how to do it ?? Been googling this for hours now and I can't find something that doesn't give a parse error. I found this thread: http://www.phpfreaks.com/forums/index.php?topic=160855 ..and tried to work around the answer but with no luck. All I really want to do is something like this: <td class=" <?php if ($time<20:00&>1:00) { echo "class1";} else if($time>20:00&<2:00) { echo "class2";}?> "></td> I want the class to change to another one if the user see the table cell within a specific hour of the day. I created a "statistics of site" page, stats.php. Currently stats.php updates every visit, that's over 25 queries for every visit, with over 9,000 visits a day, I wish to cut down. What is the best way to make it so all queries are done every hour, therefore requiring less queries to the database? I assume the best way to go at this would be either to run a time() based script every 60 minutes and: - update this to a new field, then stats.php will require 1 query every visit, plus the 1 every hour. or - update a text file and read that each stats.php visit, meaning just the 1 query every hour. Now, I understand the second option will run much less queries overall, but is it the best way to go? Is there a better way to go about doing this? Hi guys, Im a newb here, so bear with me! Still learning the ropes. I want to delete all files from my server that are 6 hours old since being uploaded to the site. I believe i need a cron job? I currently have this script in its framework... Code: [Select] <?php //time interval for deletion to occur... $x = 30; //timestamp $current_time = time(); //the file you wish to delete $file_name = 'file.txt'; //timestamp $file_creation_time = filemtime($filename); //extract difference $difference = $current_time - $file_creation_time; //if difference = $x...then delete file if ($difference == $x) { unlink($file_name); } Would that work automatically or would it need a cron to run it? And how could i test it, that bit worries me. Many thanks. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=317036.0 Maybe some of the great coders here can help this noob out. So here is what I have so far: Code: [Select] //set age criteria for deletion $age = 60; //get current date $datenow = date("Y-m-d"); //set the range we want to delete $delete_range = $datenow - $age; //get old user_id from users table $oldusers_users = mysql_query ("SELECT user_id FROM users WHERE lastvisit < $delete_range "); //get user_id from images table that correspond to users table $oldusers_images = mysql_query ("SELECT user_id FROM images WHERE $oldusers_users=user_id.images "); //find folders that correspond to the usernames and delete $oldusers_files = mysql_query ("SELECT username FROM users WHERE lastvisit < $delete_range "); //print out username //$result = mysql_($oldusers_files); $foldername = mysql_result($oldusers_files, 0); $sigspath = "sigs/"; unlink($sigspath . $foldername . ".gif/index.php"); rmdir($sigspath . $foldername . ".gif"); //now delete user_id's from database mysql_query("DELETE * FROM users WHERE user_id=$oldusers_users"); mysql_query("DELETE * FROM images WHERE user_id=$oldusers_images"); unset($oldusers_users, $oldusers_images, $oldusers_files, $foldername, $sigspath ); mysql_close($link); Right now it is only returning the first entry, not the entire list that meets the criteria. It does delete that one file though but does not remover the rows from the database. I am sure the database stuff is jacked up I am really new to that part. What am I doing wrong here or is there a better way to do this perhaps I would really appreciate help and I hope my problem can be solved easily. I am attempting to display the date/time based on the user's location. I have installed the timezone.js plugin for help as well. Is there a way to convert the Jquery variable that displays the users timezone location and insert it inside the PHP date_default_timezone_set?
If there is an easier way to display the users timezone date and time please let me know otherwise this was the only solution I could find.
Thanks in advanced...
Here is my code
Header
<header> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> <script src="Time/detect_timezone.js"></script> <script src="Time/jquery.detect_timezone.js"></script> <script> $(document).ready(function(){ $('#tzvalue').set_timezone({'default' : 'America/Los_Angeles'}); }); </script> </header> This code works just fine to display a list of reservations for a given day and sums the guest and table counts just fine for the entire day. Sums all reservations returned.
What I am trying to do or figure out is a way to get totals based on specific time intervals. For example how many guests and tables at 8:00, 9:00, 10:00, etc....
I can see where the sums are calculated, but need help adding a way to add a variable to look at the reservation_time and sum by hour rather than just daily total.
$tablesum ++; $guestsum += $row->reservation_pax; <?php echo $guestsum;?> <?php echo _guest_summary;?>The full code that pulls in the data and then sums it up in total: <!-- Begin reservation table data --> <br/> <table class="global resv-table-small" cellpadding="0" cellspacing="0"> <tbody> <tr> <?php echo "<td class='noprint'> </td>"; echo "<td>Time</td>"; echo "<td>Guests/Type</td>"; echo "<td>Name</td>"; echo "<td>Special Instructions/Notes</td>"; echo "<td class='noprint'>Table</td>"; echo "<td class='noprint'>Status</td>"; echo "<td class='noprint'>Created</td>"; echo "<td class='noprint'>Details/Delete</td>"; echo "</tr>"; // Clear reservation variable $reservations =''; if ($_SESSION['page'] == 1) { $reservations = querySQL('all_reservations'); }else{ $reservations = querySQL('reservations'); } // reset total counters $tablesum = 0; $guestsum = 0; if ($reservations) { //start printing out reservation grid foreach($reservations as $row) { // reservation ID $id = $row->reservation_id; $_SESSION['reservation_guest_name'] = $row->reservation_guest_name; // check if reservation is tautologous $tautologous = querySQL('tautologous'); echo "<tr id='res-".$id."'>"; echo "<td"; // daylight coloring if ($row->reservation_time > $daylight_evening){ echo " class='evening noprint'"; }else if ($row->reservation_time > $daylight_noon){ echo " class='afternoon noprint'"; }else if ($row->reservation_time < $daylight_noon){ echo " class='morning noprint'"; } echo " style='width:10px !important; padding:0px;'> </td>"; echo "<td id='tb_time'"; // reservation after maitre message if ($row->reservation_timestamp > $maitre['maitre_timestamp'] && $maitre['maitre_comment_day']!='') { echo " class='tautologous' title='"._sentence_13."' "; } echo ">"; echo "<strong>".formatTime($row->reservation_time,$general['timeformat'])."</strong></td>"; echo "<td id='tb_pax'><strong class='big'>".$row->reservation_pax."</strong> <span class='noprint'>"; printType($row->reservation_hotelguest_yn); //echo "<img src='images/icons/user-silhouette.png' class='middle'/>"; echo "</span></td><td style='width:10%' id='tb_name'><span class='noprint'>".printTitle($row->reservation_title)."</span><strong> <a id='detlbuttontrigger' href='ajax/guest_detail.php?id=".$id."'"; // color guest name if tautologous if($tautologous>1){echo" class='tautologous tipsy' title='"._tautologous_booking."'";} echo ">".$row->reservation_guest_name."</a></strong>"; // old reservations symbol if( (strtotime($row->reservation_timestamp) + $general['old_days']*86400) <= time() ){ echo "<img src='images/icons/clock-bolt.png' class='help tipsyold middle smicon' title='"._sentence_11."' />"; } // recurring symbol if ($row->repeat_id !=0) { echo " <img src='images/icons/loop-alt.png' alt='"._recurring. "' title='"._recurring."' class='tipsy' border='0' >"; } echo"</td><td style='width:10%' id='tb_note'>"; if ($_SESSION['page'] == 1) { echo $row->outlet_name; }else{ echo $row->reservation_notes; } echo "</td>"; if($_SESSION['wait'] == 0){ echo "<td class='big tb_nr' style='width:85px;' id='tb_table'><img src='images/icons/table_II.png' class='tipsy leftside noprint' title='"._table."' /><div id='reservation_table-".$id."' class='inlineedit'>".$row->reservation_table."</div></td>"; } echo "<td class='noprint'><div>"; getStatusList($id, $row->reservation_status); echo "</div></td>"; echo "<td class='noprint'>"; echo "<small>".$row->reservation_booker_name." | ".humanize($row->reservation_timestamp)."</small>"; echo "</td>"; echo "<td class='noprint'>"; // MOVE BUTTON // echo "<a href=''><img src='images/icons/arrow.png' alt='move' class='help' title='"._move_reservation_to."'/></a>"; // WAITLIST ALLOW BUTTON if($_SESSION['wait'] == 1){ $leftspace = leftSpace(substr($row->reservation_time,0,5), $availability); if($leftspace >= $row->reservation_pax && $_SESSION['outlet_max_tables']-$tbl_availability[substr($row->reservation_time,0,5)] >= 1){ echo" <a href='#' name='".$id."' class='alwbtn'><img src='images/icons/check-alt.png' name='".$id."' alt='"._allow."' class='help' title='"._allow."'/></a> "; } } // EDIT/DETAIL BUTTON echo "<a href='?p=102&resID=".$id."'><img src='images/icons/pen-fill.png' alt='"._detail."' class='help' title='"._detail."'/></a> "; // DELETE BUTTON if ( current_user_can( 'Reservation-Delete' ) && $q!=3 ){ echo"<a href='#modalsecurity' name='".$row->repeat_id."' id='".$id."' class='delbtn'> <img src='images/icons/delete.png' alt='"._cancelled."' class='help' title='"._delete."'/></a>"; } echo"</td></tr>"; $tablesum ++; $guestsum += $row->reservation_pax; } } ?> </tbody> <tfoot> <tr style="border:1px #000;"> <td class=" noprint"></td><td></td> <td colspan="2" class="bold"><?php echo $guestsum;?> <?php echo _guest_summary;?></td> <td></td> <td colspan="2" class="bold"><?php echo $tablesum;?> <?php echo _tables_summary;?></td> <?php if($_SESSION['wait'] == 0){ //echo "<td></td>"; } ?> </tr> </tfoot> </table> <!-- End reservation table data --> Edited by mfandel, 26 October 2014 - 02:06 AM. Hi, i am thinking of creating a text based game mmorpg using php/mysql etc... I know that a lot of these types of games use a tick based system, but i want it to be realtime, the only game i cna find that uses this is Torn, does anyone know how they make it realtime? I know that ticks can be controlled by cronjobs, but how about realtime? The problem is that the game might involve the player building a house, in a tick based system it could be easy to manage by saying the house will take 3 ticks to complete, but i want the house to be like in 10 minutes of 32 minutes, how can i do this. Someone said to check whenever the player next logs in to check if the house has finished and then say it has been built, but seeing as it is an mmorpg it could affect everyones gameplay, not just the person building it, so this will not work. Thanks and sorry if this is a bit confusing. Hi, I have a project where i want to send the sms to the customers at the particular time calling from the database, how to do these in php? Thanks, I'm working on a project that has a lot of different timezone options, and all I have from the users is their UTC offset. After weeks of doing tweaks, I come to new issues every time I add something, one would think it would be a lot easier to just get the correct time and day :) The latest issue is that when I try to rewrite a date to a better fomat, it disregards the GMT offset. Like this: 4/14/19, 12:00 PM GMT+2 (=$date) becomes ... 14-04-2019 10:00 when using this code: $bp_date_to_format = date_create_from_format('Y-m-d\TH:i:sP', $date); echo date_format($bp_date_to_format, 'd-m-Y H:i'); I figured it would just rewrite the format, keeping the exact time. It isn't. We do have all these sorts of localization functions as well, but because there doesn't seem to be one single standard (each 3rd party API connection we have uses its own default datetime format so it seems). // Remove UTC Text $UTC_offset = str_replace('UTC', '', $timezone); // Get Offset in Minutes if (stripos($UTC_offset, ':') !== false) { // Calculate seconds from offset list($hours, $minutes) = explode(':', $offset); $seconds = $hours * 60 * 60 + $minutes * 60; } else { $seconds = $UTC_offset * 60 * 60; } // Get User timezone name from seconds $timezone = timezone_name_from_abbr('', $seconds, 1); if ($timezone === false) { $timezone = timezone_name_from_abbr('', $seconds, 0); } // Set new TZ return date_default_timezone_set($timezone);
Isn't there any "one way"solution that can be used? It's confusing to say the least.
Cheers. Hi, I'm automating a process of Inserting a CSV to a database. I'm doing it in PHP. I need to go to http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/ and get the list of the files in this directory. Which is the best way of doing it in PHP? Best Regards, I am trying to find a script that will show just the file names of files in a specific directory. I tried this code posted previously on this forum and it works but shows the directory name. Code: [Select] <?php filesInDir('attachments'); function filesInDir($tdir) { $dirs = scandir($tdir); foreach($dirs as $file) { if (($file == '.')||($file == '..')) { } elseif (is_dir($tdir.'/'.$file)) { filesInDir($tdir.'/'.$file); } else { echo $tdir.'/'.$file."<br>"; } } } ?> Result is: attachments/Sedona_and_Slot_Canyon_links.docx Thanks for the help. Hi im using ftp_rawlist () to list files in my web hosting folder /public_html/ it works fine, but is there anyway to only show/list .php & html files? Base Creative is changing and expanding. We have recently appointed a new creative director and a new technical project manager and we are looking for a:
WEB DEVELOPER
Growth in our business has brought about the impetus to change the creative direction of the company along with the environment and atmosphere, under the direction of our creative head and with your input.
We have a good reputation, a wealth of happy clients - big established names to smaller start-ups with fresh ideas - but we want to be more innovative, fun and much more creative, growing further into cross media and device skills, forging a recognised, stellar reputation for quality creativity in the industry. We are starting with gradually overhauling our own website and studio, so be prepared to play a part in this change immediately.
Your Role
You will have full control over your output, from the planning stage right through to the back end development, while working with our other staff on the creative and development team. You can become a part of something new and exciting, playing a key role in shaping the environment within which you work.
The perfect candidate will be 100% committed to a successful career with Base Creative, looking to learn and grow in knowledge and have a great portfolio underpinned by varied technical skills.
Responsibilities and Tasks: I've been researching online resources and seen a lot of code and functions for calculating an interval or difference between two date/time figures. What I'm trying to do is somewhat in reverse... I want to establish an interval to determine a past date/time to be used in a MySQL Query but just can't figure the critical part.
// STEP #1 = DEFINE THE DESIRED DATE/TIME DIFFERENCE INTERVAL DESIRED FOR QUERIES $timeinterval = '60'; // Interval is in MINUTES and can be changed as desired // STEP #2 = GET THE CURRENT LOCAL SERVER DATE/TIME // as YYYY-MM-DD HH:MN:SE $serverdatetime = date('Y-m-d H:i:s'); // My local Server Date & time // STEP #3 = CALCULATE THE ***PAST** (OLDER) DATE/TIME LIMIT BASED ON $timeinterval (Minutes) // as YYY-MM-DD HH:MN:SE $pastdatetime = [stuckinarut here] <- 60 MINUTES prior to current Server Date/Time // STEP #4 = MySQL QUERY (`submitted` column is auto-timestampped on record insertions) $sql="[columnsblahblah] FROM mydb WHERE `submitted` >= $pastdatetime";In a Perfect World, the MySQL Query would yield ONLY records with a `submitted` DATE/TIME equal to 60 Minutes (or less) PRIOR TO from the Current Server Time. Any assistance is appreciated! Thanks. -FreakingOUT |