PHP - How To Get The Date From Filenames?
Hi,
I have the following situation: Code: [Select] Array ( [5] => GeoLiteCity_20090601.zip [6] => GeoLiteCity_20090701.zip [7] => GeoLiteCity_20090801.zip [8] => GeoLiteCity_20090901.zip [9] => GeoLiteCity_20091001.zip [10] => GeoLiteCity_20091101.zip [11] => GeoLiteCity_20091201.zip [12] => GeoLiteCity_20100101.zip [13] => GeoLiteCity_20100201.zip [14] => GeoLiteCity_20100301.zip [15] => GeoLiteCity_20100401.zip [16] => GeoLiteCity_20100501.zip [17] => GeoLiteCity_20100601.zip [18] => GeoLiteCity_20100701.zip [19] => GeoLiteCity_20100801.zip [20] => GeoLiteCity_20100901.zip [21] => GeoLiteCity_20101001.zip [22] => GeoLiteCity_20101101.zip [23] => GeoLiteCity_20101201.zip ) I have this array with filenames, the patern for the name of the file is NAME_DATE.zip I need to get from this array the most recent file(GeoLiteCity_20101201.zip). Which is the best way of doing this task? Give me some clues. Best Regards, Similar TutorialsI could use some help on naming my PHP files... The approach I have settled on for now is that I have some PHP page that does something (e.g. "change_password.php") and then another page to which the user is redirected (e.g. "change_password_results.php") which displays an outcome message like "Your Password has been re-set." Questions: 1.) Is it a problem having multi-word PHP File Names? 2.) Is it a problem separating them with underscores? 3.) Will it look *strange* to users looking at the URL to see a file name like "create_account_results.php" ?? 4.) Will this impact SEO? Thanks, Debbie Hello PHPFreaks! I have a question for somebody to answer Code: [Select] <?php //This is the directory where images will be saved $target = "gallery/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $username=$_POST['username']; $photo=($_FILES['photo']['name']); $caption=$_POST['caption']; $ip=$_POST['ip']; //Writes the information to the database mysql_query("INSERT INTO `photo` (username, photo, caption, ip) VALUES ('$username', '$photo', '$caption', '$ip')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your caption has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> When pictures are uploaded; they upload the name they have named them. Is it possible to add to the script $username somewhere to the file name? For example; DSC_0077_SOLAR.JPG Thanks for your time! Hi, I've tried various methods (ie. glob etc.) but haven't had any success, the purpose is to scan through all directories for php files, then place those php files along with their path ($dir/$filename) into an array (to use elsewhere) So if I have the following file/directory structure (example): Code: [Select] --forums: ---topic.php ---forum.php --func: ---functions.php Would produce the following array: $files = array('topic.php' => 'forums/topic.php', 'forum.php' => 'forums/forum.php' 'functions.php' => 'func/functions.php'); Hi all I hope I have come to the right place. My system reads files stored on a drive and lists them to users through plain HTML, I made it 11 years ago and have to refresh my memory. My problem is that filenames seem to come in different formats, to how to decode/encode them is an issue...
My users use Scandinavian letters (æøåäöüõ) and it seems like one filename is in one format and another in another format. There is no logic to what format the filenames comes it. All files are ok and downloads as they should, they just dont list well. Any idea how I can handle this issue?
Hello:
How could I use php to automatically insert the correct 3 letter month abbreviations and four digit year in the following pdf filenames on the first of each month?
(For example "...Feb2015.pdf" then "...Mar2015.pdf" and so on....
<div>Book One: <a href="http://monthlybookfi...One_Jan2015.pdf">Download Here</a></div> <div>Book Two: <a href="http://monthlybookfi...Two_Jan2015.pdf">Download Here</a></div> <div>Book Three: <a href="http://monthlybookfi...ree_Jan2015.pdf">Download Here</a> </div> <div>Book Four: <a href="http://monthlybookfi...our_Jan2015.pdf">Download Here</a> </div> Please advise, Eggie I need to display multiple files that have a similar file name, but there are timestamps added to the filename once its been modified. What could I use in PHP to display all these files? Right now I use a $path variable that looks into a SQL table to build the path to the folder that the files reside in.. ELSEIF($Recordmyrow['Applicatio'] == "pdf file") { IF($securityvalue != "P"){$display = false;} IF(file_exists(substr($path, 5))){} ELSE{$column4 = "<A href='javascript:mbox();'>UNAVAILABLE</A>";} } So there is a file called file1.pdf then another one called file1.mmddyyyy.pdf My code shows file1.pdf but not file1.mmddyyyy.pdf Is there some kind of wildcard I can use to get it to show all the files if they exist? Hey Guys, I want to be able to upload a large amount of mp3's to a private area on our website and have a script that will scan the folder for all the filenames and then create a record in the db of all the filenames. It is to help with creating the playlist for my friends radio show. To manually insert all the filenames each month woudl be a nightmare! I have been messing with a partial script I found on the web, and it kind of does something but not what I want it to. heres the db id int(4) title varchar(250) mp3 varchar(250) sort int(4) visible int(1) added datetime heres the script i am trying to use: <? $listDir = array(); $dir = "./music"; if($handler = opendir($dir)) { while (($sub = readdir($handler)) !== FALSE) { if ($sub != "." && $sub != ".." && $sub != "Thumb.db") { if(is_file($dir."/".$sub)) { $listDir[] = $sub; }elseif(is_dir($dir."/".$sub)){ $listDir[$sub] = $this->ReadFolderDirectory($dir."/".$sub); } } } closedir($handler); } $db = mysql_connect("localhost","gfab_ml","xxxxxxx"); mysql_select_db("gfab_ml",$db); $colors=serialize($listDir); //takes the data from a post $sql="INSERT INTO ml_music (ID, title, added) VALUES('','$colors','')"; $result = mysql_query($sql) or die (mysql_error()); ?> it does insert the values into the db but what it does is creates 1 record and spits all the results in a really weird way like this. into the title field. a:18:{i:0;s:23:"14 Mr Magic Premier.mp3";i:1;s:23:"track1.mp3";i:2;s:15:"track2.jpg";i:3;s:15:"track3.fxp";i:4;s:12:"track4.mp3";i:5;s:7:"track5.mp3";i:6;s:7:"track6.jpg";i:7;s:7:"track7.mp3";i:8;s:12:"track8.mp3" Could anyone please help me to make it work? im a bit of a noob. but i do like to tinker! Hi All I'm after some advice about how to write a parser to match many different naming formats of a tv episode, so the one thing we can rely on is that a episodes are inside a folder named after the show, for example "House MD\episode name. s1e07.mkv" so we know the show name, that part is easy, the bit I need to match is the season and episode number. The format of the file name can differ is so many ways, here are some examples: - S01E01 - s1e10 - S3e6 - 105 (for season 1, episode 5) - EP01 (usually there's one season in this case, but not 100% of the time) So as you can see there are a few variations, almost always the show name is in there too, and sometimes they contain resolution, so: House.MD S1E09 720p HD.mkv, there are many combinations but since we already know the show name it's not something I think we need to worry *too* much about. My question relations to how you would approach this? You can see from the examples above sometimes this would be hard to match and work out. My initial idea would be to have a class called 'tvmatcher', or something, which has match handlers, one match handler for each format we need match, a handler would be a class that extends tvmatcher and have the same method, like $handler->match($string); the first one to match would be the winner. This could be extended to sanity check the result and ensure that the season/ep actually exists. I really don't know how to go about this, the idea above is my best so far, so again my questions really a How would you approach this? Is there a pattern that would help? any other ideas about how this could be acheived? It's worth noting that I'd be using external APIs to get show information, but would be out of the scope of this library, but could help with said sanity checks. Cheers, Billy Hi guys. Just a quick PHP question. I have a script running that gets the files from a directory. There is then a switch function that decides what to do with the file, ie... if it is a PNG... DO THIS.. if it is a docx... DO THIS.. etc. And i want each file to be in a different cell on the table. The table can be longer wider than 5 columns (however it can be as high as it wants). I currently have this bit working... but instead of one item in each cell... it is displaying every item in each cell. Any ideas Chaps? Here is my code Many thanks in advance if you could possibly help.. echo "<table><tr>"; $count = count(glob("../../shared/files/*.*", GLOB_BRACE)); for($i=1; $i <= $count; $i++) { /// echo "<td>"; /// if ($handle = opendir('../../shared/files/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $break = pathinfo($file); $b = $break['extension']; switch (@$break[extension]) { case 'bmp' : echo 'A BMP<br>'; break; case 'png' : echo 'A PNG<br>'; break; case 'doc' : case 'docx' : echo 'A DOC OR DOCX<br>'; break; default: echo 'FILE NOT RECOGNISED<br>'; } } } closedir($handle); } /// echo "</td>"; /// if($i % 3 == 0) echo "</tr><tr>"; } echo "</tr></table>"; ?> Hey, I'm using a script which allows you to click on a calendar to select the date to submit to the database. The date is submitted like this: 2014-02-08 Is there a really simple way to prevent rows showing if the date is in the past? Something like this: if($currentdate < 2014-02-08 || $currentdate == 2014-02-08) { } Thanks very much, Jack Hello. I'm new to pHp and I would like to know how to get my $date_posted to read as March 12, 2012, instead of 2012-12-03. Here is the code: Code: [Select] <?php $sql = " SELECT id, title, date_posted, summary FROM blog_posts ORDER BY date_posted ASC LIMIT 10 "; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { $id = $row['id']; $title = $row['title']; $date_posted = $row['date_posted']; $summary = $row['summary']; echo "<h3>$title</h3>\n"; echo "<p>$date_posted</p>\n"; echo "<p>$summary</p>\n"; echo "<p><a href=\"post.php?id=$id\" title=\"Read More\">Read More...</a></p>\n"; } ?> I have tried the date() function but it always updates with the current time & date so I'm a little confused on how I get this to work. Alright, I have a Datetime field in my database which I'm trying to store information in. Here is my code to get my Datetime, however it's returning to me the wrong date. It's returning: 1969-12-31 19:00:00 $mysqldate = date( 'Y-m-d H:i:s', $phpdate ); $phpdate = strtotime( $mysqldate ); echo $mysqldate; Is there something wrong with it? I have tried a large number of "solutions" to this but everytime I use them I see 0000-00-00 in my date field instead of the date even though I echoed and can see that the date looks correct. Here's where I'm at: I have a drop down for the month (1-12) and date fields (1-31) as well as a text input field for the year. Using the POST array, I have combined them into the xxxx-xx-xx format that I am using in my field as a date field in mysql. <code> $date_value =$_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']; echo $date_value; </code> This outputs 2012-5-7 in my test echo but 0000-00-00 in the database. I have tried unsuccessfully to use in a numberof suggested versions of: strtotime() mktime Any help would be extremely appreciated. I am aware that I need to validate this data and insure that it is a valid date. That I'm okay with. I would like some help on getting it into the database. (continuing from topic title) So if I set a date of July 7 2011 into my script, hard coded in, I would like the current date to be checked against the hard coded date, and return true if the current date is within a week leading up to the hard coded date. How could I go about doing this easily? I've been researching dates in php but I can't seem to work out the best way to achieve what I'm after. Cheers Denno Hi, I have a job listing website which displays the closing date of applications using: $expired_date (This displays a date such as 31st December 2019) I am trying to show a countdown/number of days left until the closing date. I have put this together, but I can't get it to show the number of days. <?php $expired_date = get_post_meta( $post->ID, '_job_expires', true ); $hide_expiration = get_post_meta( $post->ID, '_hide_expiration', true ); if(empty($hide_expiration )) { if(!empty($expired_date)) { ?> <span><?php echo date_i18n( get_option( 'date_format' ), strtotime( get_post_meta( $post->ID, '_job_expires', true ) ) ) ?></span> <?php $datetime1 = new DateTime($expired_date); $datetime2 = date('d'); $interval = $datetime1->diff($datetime2); echo $interval->d; ?> <?php } } ?> Can anyone help me with what I have wrong? Many thanks Hi Guys.. How can I change a date on the fly ? Everything is UTC on my server. How can I change a date to something else on the fly? Ie: $timezone = "cet"; $datetime = "2011-09-04 19:53:00"; echo $datetime($timezone); So I can give it a datetime and have it echo the datetime as if it were in the other timezone? Thanks Graham i have a table that shows payments made but want to the payments only showing from a set date(06/12/14) and before this date i dont want to show
this is my sql that doesnt seem to work and is showing dates before the specified date.
.
"SELECT * FROM payments2014, signup2014, editprop2014 WHERE signup2014.userid = payments2014.payment_userid AND editprop2014.prop_id = signup2014.prop_id AND signup2014.userid !='page1' AND signup2014.userid !='page6' AND signup2014.userid !='page4' AND payments2014.payment_transaction_status !='none' AND payments2014.payment_transaction_status !='CANCELLEDa' AND payments2014.payment_type !='deposit' AND payments2014.payment_paid_timestamp NOT LIKE '%2012%' AND payments2014.payment_paid_timestamp NOT LIKE '%2011%' AND payments2014.payment_paid_timestamp >= '06/12/14' ORDER BY payments2014.payment_id DESC"i have some other parts in the statment but this one that should be filtering is host_payments2014.payment_paid_timestamp >= '06/12/14'thanks in advance Hi, I am trying to convert a String date into numeric date using PHP function's, but haven't found such function. Had a look at date(), strtotime(), getdate(); e.g. Apr 1 2011 -> 04-01-2011 Could someone please shed some light on this? Regards, Abhishek I'm getting this Time Zone error. Perhaps it's a compatibility issue with PHP 5.3. Looked all over for an answer without finding one. Here is the error message Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EST/-5.0/no DST' instead in /blocked.php on line 41 12/02/12 Here is the code. Line 41 is near the bottom, the one with the d,m,y. Perhaps the echo date (d/m/y") needs to be changed. Appreciate any help! Code: [Select] <table border="3" width="16%" align="center" cellspacing="0" bgcolor="#FF6600" bordercolor="red" bordercolordark="red" bordercolorlight="red"> <tr> <td width="176"> <p align="center"><?php // shows IP Number on Page echo $ip; ?> </p> </td> </tr> </table> <p align="center"><?php // Show the user agent echo 'Your user agent is: <b>'.$_SERVER['HTTP_USER_AGENT'].'</b><br />';?></p> [b]<h1 align="center"><?php echo date("d/m/y");?></h1>[/b] </td> </tr> </table [,code] |