{"id":55,"date":"2017-10-14T16:52:00","date_gmt":"2017-10-14T15:52:00","guid":{"rendered":"https:\/\/jmfweather.uk\/blog\/?p=55"},"modified":"2021-07-14T16:54:07","modified_gmt":"2021-07-14T15:54:07","slug":"php-coding-five-hours-of-work-for-ten-lines-of-code","status":"publish","type":"post","link":"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/","title":{"rendered":"PHP Coding: Five hours of work for ten lines of code"},"content":{"rendered":"\n<p>It\u2019s taken me 5-hours of effort over the last day or two to get my <a href=\"https:\/\/jmfweather.uk\/weather34-large-cam.php\" data-type=\"URL\" data-id=\"https:\/\/jmfweather.uk\/weather34-large-cam.php\" target=\"_blank\" rel=\"noreferrer noopener\">webcam<\/a> correctly reporting a picture for my weather station.<\/p>\n\n\n\n<p>Problem: &nbsp;The Wunderground FTP process has stopped working with no sign of a resolution. I needed to provide a single image that could be referenced by Wunderground rather than FTP to their site. The trouble was that my webcam uses incremental filenames based on date-timestamp. I also needed to use the latest and get rid of any other uploads.<\/p>\n\n\n\n<p>Solution: Use the PHP code that runs my weather page and forwards the weather station page to Wunderground to, in addition, find the latest image file and after 5-minutes rename it to the static name image file and delete all the other potentially uploaded webcam files.<\/p>\n\n\n\n<p>It took a lot of trial and error to get to the code below. All the while reading the online PHP reference and other PHP examples to get to what I needed. It\u2019s not necessarily petty code but it does work.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ list the ARG*.jpg files in the webcam directory. Save to an array\n$ARCfiles = glob('..\/webcam\/ARC*.jpg');\n\/\/ reverse sort the array to get the most recent file by timestamped name\nrsort ($ARCfiles);\n\/\/ grab the first (most recent file)\n$fileselected = $ARCfiles&#91;0];\n\/\/ setup the logging file and write the selected file to the logging file\n\/\/ $latestfile = '..\/webcam\/latestwebcamfile.txt';\n\/\/ file_put_contents($latestfile, $fileselected);\n\/\/ check that the webcam image is 5-minutes old. If so overwrite it with the latest and delete all other ARC*.jpg files.\nif(file_exists('..\/webcam\/webcamimage.jpg')&amp;&amp;time()- filectime('..\/webcam\/webcamimage.jpg')&gt;300){&amp;nbsp; &amp;nbsp;\n   rename($fileselected , '..\/webcam\/webcamimage.jpg');&amp;nbsp; &amp;nbsp;\n   \/\/ list then delete every file beginning with ARC*&amp;nbsp; &amp;nbsp;\n   $files = glob('..\/webcam\/ARC*.jpg');&amp;nbsp; \n   foreach($files as $file){ \n      if(is_file($file)){ \n         unlink($file); \n      }&amp;nbsp; &amp;nbsp;\n   }\n}\n?&gt;<\/code><\/pre>\n<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_55\" class=\"pvc_stats all  \" data-element-id=\"55\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/jmfweather.uk\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p><div class=\"pvc_clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>It\u2019s taken me 5-hours of effort over the last day or two to get my webcam correctly reporting a picture for my weather station. Problem: &nbsp;The Wunderground FTP process has stopped working with no sign of a resolution. I needed to provide a single image that could be referenced by Wunderground rather than FTP toContinue reading &rarr;<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_55\" class=\"pvc_stats all  \" data-element-id=\"55\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/jmfweather.uk\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4],"tags":[],"class_list":["post-55","post","type-post","status-publish","format-standard","hentry","category-blog","category-weather","no-thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PHP Coding: Five hours of work for ten lines of code - JMFweather.UK Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP Coding: Five hours of work for ten lines of code - JMFweather.UK Blog\" \/>\n<meta property=\"og:description\" content=\"It\u2019s taken me 5-hours of effort over the last day or two to get my webcam correctly reporting a picture for my weather station. Problem: &nbsp;The Wunderground FTP process has stopped working with no sign of a resolution. I needed to provide a single image that could be referenced by Wunderground rather than FTP toContinue reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/\" \/>\n<meta property=\"og:site_name\" content=\"JMFweather.UK Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/jasonmfarrow\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/jasonmfarrow\" \/>\n<meta property=\"article:published_time\" content=\"2017-10-14T15:52:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-14T15:54:07+00:00\" \/>\n<meta name=\"author\" content=\"Jason Farrow\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@jasonmfarrow\" \/>\n<meta name=\"twitter:site\" content=\"@jasonmfarrow\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jason Farrow\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/\"},\"author\":{\"name\":\"Jason Farrow\",\"@id\":\"https:\/\/jmfweather.uk\/blog\/#\/schema\/person\/a8bfcf905b288393cdd84898e1c0daa9\"},\"headline\":\"PHP Coding: Five hours of work for ten lines of code\",\"datePublished\":\"2017-10-14T15:52:00+00:00\",\"dateModified\":\"2021-07-14T15:54:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/\"},\"wordCount\":184,\"publisher\":{\"@id\":\"https:\/\/jmfweather.uk\/blog\/#\/schema\/person\/a8bfcf905b288393cdd84898e1c0daa9\"},\"articleSection\":[\"Blog\",\"Weather\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/\",\"url\":\"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/\",\"name\":\"PHP Coding: Five hours of work for ten lines of code - JMFweather.UK Blog\",\"isPartOf\":{\"@id\":\"https:\/\/jmfweather.uk\/blog\/#website\"},\"datePublished\":\"2017-10-14T15:52:00+00:00\",\"dateModified\":\"2021-07-14T15:54:07+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jmfweather.uk\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP Coding: Five hours of work for ten lines of code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jmfweather.uk\/blog\/#website\",\"url\":\"https:\/\/jmfweather.uk\/blog\/\",\"name\":\"JMFweather.UK Blog\",\"description\":\"Clouds, Rain &amp; Wind\",\"publisher\":{\"@id\":\"https:\/\/jmfweather.uk\/blog\/#\/schema\/person\/a8bfcf905b288393cdd84898e1c0daa9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jmfweather.uk\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/jmfweather.uk\/blog\/#\/schema\/person\/a8bfcf905b288393cdd84898e1c0daa9\",\"name\":\"Jason Farrow\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/jmfweather.uk\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jmfweather.uk\/blog\/wp-content\/uploads\/2021\/07\/JMFweather_logo2_trans.jpg\",\"contentUrl\":\"https:\/\/jmfweather.uk\/blog\/wp-content\/uploads\/2021\/07\/JMFweather_logo2_trans.jpg\",\"width\":500,\"height\":500,\"caption\":\"Jason Farrow\"},\"logo\":{\"@id\":\"https:\/\/jmfweather.uk\/blog\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/jmfweather.uk\",\"https:\/\/www.facebook.com\/jasonmfarrow\",\"https:\/\/www.instagram.com\/jasonmfarrow\/\",\"https:\/\/x.com\/jasonmfarrow\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP Coding: Five hours of work for ten lines of code - JMFweather.UK Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/","og_locale":"en_GB","og_type":"article","og_title":"PHP Coding: Five hours of work for ten lines of code - JMFweather.UK Blog","og_description":"It\u2019s taken me 5-hours of effort over the last day or two to get my webcam correctly reporting a picture for my weather station. Problem: &nbsp;The Wunderground FTP process has stopped working with no sign of a resolution. I needed to provide a single image that could be referenced by Wunderground rather than FTP toContinue reading &rarr;","og_url":"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/","og_site_name":"JMFweather.UK Blog","article_publisher":"https:\/\/www.facebook.com\/jasonmfarrow","article_author":"https:\/\/www.facebook.com\/jasonmfarrow","article_published_time":"2017-10-14T15:52:00+00:00","article_modified_time":"2021-07-14T15:54:07+00:00","author":"Jason Farrow","twitter_card":"summary_large_image","twitter_creator":"@jasonmfarrow","twitter_site":"@jasonmfarrow","twitter_misc":{"Written by":"Jason Farrow","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/#article","isPartOf":{"@id":"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/"},"author":{"name":"Jason Farrow","@id":"https:\/\/jmfweather.uk\/blog\/#\/schema\/person\/a8bfcf905b288393cdd84898e1c0daa9"},"headline":"PHP Coding: Five hours of work for ten lines of code","datePublished":"2017-10-14T15:52:00+00:00","dateModified":"2021-07-14T15:54:07+00:00","mainEntityOfPage":{"@id":"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/"},"wordCount":184,"publisher":{"@id":"https:\/\/jmfweather.uk\/blog\/#\/schema\/person\/a8bfcf905b288393cdd84898e1c0daa9"},"articleSection":["Blog","Weather"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/","url":"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/","name":"PHP Coding: Five hours of work for ten lines of code - JMFweather.UK Blog","isPartOf":{"@id":"https:\/\/jmfweather.uk\/blog\/#website"},"datePublished":"2017-10-14T15:52:00+00:00","dateModified":"2021-07-14T15:54:07+00:00","breadcrumb":{"@id":"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jmfweather.uk\/blog\/2017\/10\/14\/php-coding-five-hours-of-work-for-ten-lines-of-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jmfweather.uk\/blog\/"},{"@type":"ListItem","position":2,"name":"PHP Coding: Five hours of work for ten lines of code"}]},{"@type":"WebSite","@id":"https:\/\/jmfweather.uk\/blog\/#website","url":"https:\/\/jmfweather.uk\/blog\/","name":"JMFweather.UK Blog","description":"Clouds, Rain &amp; Wind","publisher":{"@id":"https:\/\/jmfweather.uk\/blog\/#\/schema\/person\/a8bfcf905b288393cdd84898e1c0daa9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jmfweather.uk\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":["Person","Organization"],"@id":"https:\/\/jmfweather.uk\/blog\/#\/schema\/person\/a8bfcf905b288393cdd84898e1c0daa9","name":"Jason Farrow","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/jmfweather.uk\/blog\/#\/schema\/person\/image\/","url":"https:\/\/jmfweather.uk\/blog\/wp-content\/uploads\/2021\/07\/JMFweather_logo2_trans.jpg","contentUrl":"https:\/\/jmfweather.uk\/blog\/wp-content\/uploads\/2021\/07\/JMFweather_logo2_trans.jpg","width":500,"height":500,"caption":"Jason Farrow"},"logo":{"@id":"https:\/\/jmfweather.uk\/blog\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/jmfweather.uk","https:\/\/www.facebook.com\/jasonmfarrow","https:\/\/www.instagram.com\/jasonmfarrow\/","https:\/\/x.com\/jasonmfarrow"]}]}},"_links":{"self":[{"href":"https:\/\/jmfweather.uk\/blog\/wp-json\/wp\/v2\/posts\/55","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jmfweather.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jmfweather.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jmfweather.uk\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jmfweather.uk\/blog\/wp-json\/wp\/v2\/comments?post=55"}],"version-history":[{"count":1,"href":"https:\/\/jmfweather.uk\/blog\/wp-json\/wp\/v2\/posts\/55\/revisions"}],"predecessor-version":[{"id":56,"href":"https:\/\/jmfweather.uk\/blog\/wp-json\/wp\/v2\/posts\/55\/revisions\/56"}],"wp:attachment":[{"href":"https:\/\/jmfweather.uk\/blog\/wp-json\/wp\/v2\/media?parent=55"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jmfweather.uk\/blog\/wp-json\/wp\/v2\/categories?post=55"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jmfweather.uk\/blog\/wp-json\/wp\/v2\/tags?post=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}