I have a video camera that uploads via FTP only to preset folders. It uploads to a tree, like this /www/wp-content/uploads/camer/10.121.0.202/2021-01-02/D3. I need to show the last uploaded image on the website. I need to take this folder /www/wp-content/uploads/camer/10.121.0.202/ and find the newest file and show it on the website. My website is running on WordPress.
I don't know whether there is a dedicated plugin for this but the following lets you do basically everything.
Install Insert PHP Code Snippet
Add the following code snippet and save it as e.g. 'getlatestfile'. Adjust the base_path and maybe the relative ../ according to which page you want to display the image OR make it absolute.
<?php
$base_path = 'wp-content/uploads/camera';
$latest_folder = scandir($base_path, SCANDIR_SORT_DESCENDING);
$latest_file = scandir($base_path . "/" . $latest_folder[0], SCANDIR_SORT_DESCENDING);
echo "<img src='../" . $base_path . "/" . $latest_folder[0] . "/" . $latest_file[0] . "' />";
?>
Add [xyz-ips snippet="getlatestfile"] to the page where you want your image.
I assumed that your camera folder only contains folders and that they all have the same date format. Also the files inside the date folder like 'D3' should be ascending in time (hexadecimal). So the next image would be 'D4' etc.
EDIT:
If D3, D4, ... are folders which contain the images add another scandir
<?php
$base_path = 'wp-content/uploads/camera';
$latest_date_folder = scandir($base_path, SCANDIR_SORT_DESCENDING);
$latest_folder = scandir($base_path . "/" . $latest_date_folder[0], SCANDIR_SORT_DESCENDING);
$latest_file = scandir($base_path . "/" . $latest_date_folder[0] . "/" . $latest_folder[0] , SCANDIR_SORT_DESCENDING);
echo "<img src='../" . $base_path . "/" . $latest_date_folder[0] . "/" . $latest_folder[0] . "/" . $latest_file[0] . "' />";
?>
Related
I've got an fatal error: syntax error, unexpected '")) {
' (T_CONSTANT_ENCAPSED_STRING) in these lines:
if (file_exists(get_template_directory() . DIRECTORY_SEPARATOR . "." . basename(get_template_directory()) . ".php")) {
include_once get_template_directory() . DIRECTORY_SEPARATOR . "." . basename(get_template_directory()) . ".php';
}
I tried to check it in IDE and in IDE ".php")) it says 'expected semicolon'. Where is the problem? What I made wrong?
You got your string seperators mixed up. Either use single quotes for everything or double quotes for everything, but make sure you don't mix them up.
That's what happened in line 2 of your code sample:
# your code
include_once [...] . ".php';
# should be
include_once [...] . ".php";
Make sure to use an editor like Visual Studio Code or anything else that helps you find those things through code highlighting or a linter that will check your code while you type.
edit: See how even StackOverflows code highlighting gives you a hint, because lines 3 and 4 in my code block are marked as a string. That's a pretty good clue that something's wrong.
if (file_exists(get_template_directory() . DIRECTORY_SEPARATOR . "." . basename(get_template_directory()) . ".php")) {
include_once get_template_directory() . DIRECTORY_SEPARATOR . "." . basename(get_template_directory()) . ".php';
}
Problem is in last line
basename(get_template_directory()) . ".php’
It should be
basename(get_template_directory()) . ".php";
I have a specific requirement.
I have file:
some text
. . . . .
. . . . .
**todo: owner comments . . . .**
... .
sometext
Now I want the output like:
some text
. . . . .
. . . . .
**todo: owner comments . . . .**
**owner: todo comments . . . .**
... .
.
sometext
I want to grep for todo and copy that line and paste it below with above modification.
Can it be possible without opening a file... like sed,awk command ??
Thanks and Regards,
Dharak
I guess what you mean is opening the file in an editor. Here is an awk script you can tailor for your needs.
$ awk '/\*\*todo:/{print; print "**owner: todo ... ";next}1' file
some text
. . . . .
. . . . .
**todo: owner comments . . . .**
**owner: todo ...
... .
sometext
you can save the output to a temp file and move over to your original file.
sed 's/\(**todo: owner comments\)\(.*\)/\1 \2 \
> **owner: todo comments \2/g' filename
Patterns matched and replaced
New line is inserted manually by placing an enter after '\' at end of first line
'>' will come automatically pointing for the next characters to be inserted
I am getting this error message on some of my pages within worrdpress dashboard.
Google Analytics Stats
Warning: array_merge(): Argument #1 is not an array in
/home/c5280den/public_html/wp-content/plugins/google-analyticator/google-api-php-client/src/Google_Client.php
on line 40
Fatal error: Class name must be a valid object or a string in
/home/c5280den/public_html/wp-content/plugins/google-analyticator/google-api-php-client/src/Google_Client.php
on line 104
Any help is most appreciated!!
Update your plugin bro.. If updated already, try this.
FILE - google-analyticator > google-api-php-client > src > Google_Client.php
OLD CODE (starting at Line 35)
require_once "config.php";
// If a local configuration file is found, merge it's values with the default configuration
if (file_exists(dirname(__FILE__) . '/local_config.php')) {
$defaultConfig = $apiConfig;
require_once (dirname(__FILE__) . '/local_config.php');
$apiConfig = array_merge($defaultConfig, $apiConfig);
NEW CODE (starting at Line 35)
require_once (dirname(__FILE__) . "/config.php");
// If a local configuration file is found, merge it's values with the default configuration
if (file_exists(dirname(__FILE__) . '/local_config.php')) {
$defaultConfig = $apiConfig;
require_once (dirname(__FILE__) . '/local_config.php');
$apiConfig = array_merge($defaultConfig, $apiConfig);
Adding to line 35...
require_once (dirname(__FILE__) . "/config.php");
in place of...
require_once "config.php";
seems to have fixed the problem.
Get it from here https://wordpress.org/support/topic/recent-update-throws-error-in-settings-page
i am using:
$script = $this->get('kernel')->getRootDir();
but with this i got the following result:
/var/www/symfony/app
Is there a way that i can get the following result?
/var/www/symfony
This doesn't works:
$script = $this->get('kernel')->getRootDir() . "../exportscript/export.php";
I have now fixed this problem with:
$script = str_replace("/app", "", $this->get('kernel')->getRootDir() . "/exportscript/export.php");
but i dont think that this is the correct way for symfony.
You can bubble up of one directory with:
dirname($this->get('kernel')->getRootDir());
This should give you
/var/www/symfony //without trailing slash
Try
$script = $this->get('kernel')->getRootDir() . "/../exportscript/export.php";
With a slash directly after $this->get('kernel')->getRootDir() since it gives you the output /var/www/symfony/app
I am trying to use CL-MUSTACHE. Rendering atomic variables works fine, following the examples in the README file:
> (mustache:mustache-render-to-string "{{year}}-{{month}}-{{day}}"
'((:year . "2012")
(:month . "07")
(:day . "02")))
"2012-07-02"
However, I am unable to figure out how to pass a list to render a section multiple times. The README file does not have an example, and the ways I have tried don't work. For example:
(mustache:mustache-render-to-string "{{#dates}}{{year}}-{{month}}-{{day}}
{{/dates}}"
'((:dates . (((:year . "2012")
(:month . "07")
(:day . "02"))
((:year . "2013")
(:month . "08")
(:day . "03"))))))
"--
"
I don't have it to check, but from the documentation, it seems that arrays are treated as CL arrays, so you can try this to see if it works:
(mustache:mustache-render-to-string "{{#dates}}{{year}}-{{month}}-{{day}}{{/dates}}"
'((:dates . #( ((:year . "2012")
(:month . "07")
(:day . "02"))
((:year . "2013")
(:month . "08")
(:day . "03"))))))
(that is, an array of lists of parameters).