Einbindung von PHP Skript funktioniert nur in Vorschau korrekt
-
Hallo zusammen
Vorab: Falls die Frage im falschen Forum ist, bitte verschieben. Es ist auch ein Plugin im Spiel, jedoch habe ich dieses Problem auch ohne Plugin..
Ich möchte für einen Skilift eine neue Webseite erstellen mit WordPress, gehostet auf einem Synology NAS. Der grösste Knackpunkt dabei ist die Einbindung des bestehenden Webcam-Bilds in WordPress.
Lange war das Webcam-Bild (https://webcam.synology.me/cam/ als iFrame eingebunden, was jedoch zu Problemen in der Mobile-Ansicht geführt hat. Neu möchte ich daher das neuste Bild direkt anzeigen lassen.
Grundlage dafür ist folgendes PHP Skript:
function getLatestImage($folderName, $imageEnding) { $newest_mtime = 0; $base_url = $folderName; $file_ending = $imageEnding; $show_file = 'images/folio/no-image.jpg'; if ($handle = opendir($base_url)) { while (false !== ($latestFile = readdir($handle))) { if (($latestFile != '.') && ($latestFile != '..') && ($latestFile != '.htaccess') && (strpos($latestFile, $file_ending))) { $mtime = filemtime("$base_url/$latestFile"); if ($mtime > $newest_mtime) { $newest_mtime = $mtime; $show_file = "$base_url/$latestFile"; } } } } return $show_file; } echo '<img src="' .getLatestImage("../pics", '.jpg'). '" alt="Latest from the web">';
Dieses PHP Skript (was nichts anderes macht, als das neuste .jpg im angegebenen Ordner anzuzeigen) habe ich mit dem Plugin „XYZ PHP Code“ eingefügt, und den dazugehörigen Snippet Short Code auf der Seite eingefügt. Zurzeit verwende ich Elementor, wo auch solche Short-Codes eingefügt werden können.
Interessant ist nun, dass die Anzeige in der Vorschau funktioniert, nicht aber wenn ich die Änderungen abspeichere und dann normal auf die Seite navigiere.
Anbei ein Screenshot von der Vorschau, wo es funktioniert:
https://ibb.co/Mg0TzDZIch kann mir vorstellen, dass es mit dem relativen Pfad (../pics) zu tun hat. Ich habe damit auch schon gespielt, es jedoch nie geschafft, dass das Bild wirklich angezeigt wird. Wie kann ich das lösen?
Anbei noch der Auszug meiner WordPress Seite
### wp-core ### version: 5.8.3 site_language: de_CH user_language: de_CH timezone: +00:00 permalink: /%year%/%monthnum%/%day%/%postname%/ https_status: true multisite: false user_registration: 0 blog_public: 1 default_comment_status: open environment_type: production user_count: 1 dotorg_communication: true ### wp-paths-sizes ### wordpress_path: /volume1/web_packages/wordpress wordpress_size: 46.23 MB (48476818 bytes) uploads_path: /volume1/web_packages/wordpress/wp-content/uploads uploads_size: 234.04 kB (239660 bytes) themes_path: /volume1/web_packages/wordpress/wp-content/themes themes_size: 7.76 MB (8134221 bytes) plugins_path: /volume1/web_packages/wordpress/wp-content/plugins plugins_size: 25.48 MB (26722936 bytes) database_size: 3.46 MB (3628068 bytes) total_size: 83.16 MB (87201703 bytes) ### wp-active-theme ### name: Hello Elementor (hello-elementor) version: 2.6.1 author: Elementor Team author_website: https://elementor.com/?utm_source=wp-themes&utm_campaign=author-uri&utm_medium=wp-dash parent_theme: none theme_features: core-block-patterns, widgets-block-editor, menus, post-thumbnails, automatic-feed-links, title-tag, html5, custom-logo, editor-style, align-wide, woocommerce, wc-product-gallery-zoom, wc-product-gallery-lightbox, wc-product-gallery-slider theme_path: /volume1/web_packages/wordpress/wp-content/themes/hello-elementor ### wp-themes-inactive (4) ### Twenty Nineteen: version: 1.7, author: the WordPress team (latest version: 2.4) Twenty Seventeen: version: 2.4, author: the WordPress team (latest version: 3.1) Twenty Twenty: version: 1.5, author: the WordPress team (latest version: 2.1) Twenty Twenty-One: version: 1.3, author: the WordPress team (latest version: 1.7) ### wp-mu-plugins (1) ### Disable XML-RPC Pingback: version: 1.1, author: Samuel Aguilera ### wp-plugins-active (2) ### Elementor: version: 3.9.2, author: Elementor.com (latest version: 3.10.0) Insert PHP Code Snippet: version: 1.3.3, author: xyzscripts.com ### wp-plugins-inactive (3) ### Akismet Anti-Spam: version: 4.1.7, author: Automattic (latest version: 5.0.2) Hello Dolly: version: 1.7.2, author: Matt Mullenweg WordPress Importer: version: 0.6.1, author: wordpressdotorg (latest version: 0.8) ### wp-media ### image_editor: WP_Image_Editor_GD imagick_module_version: 1691 imagemagick_version: ImageMagick 6.9.11-22 Q8 x86_64 20200626 https://imagemagick.org imagick_version: @PACKAGE_VERSION@ file_uploads: File uploads is turned off post_max_size: 32M upload_max_filesize: 32M max_effective_size: 32 MB max_file_uploads: 20 gd_version: bundled (2.1.0 compatible) gd_formats: GIF, JPEG, PNG, BMP ghostscript_version: not available ### wp-server ### server_architecture: Linux 4.4.180+ x86_64 httpd_software: Apache/2.4.51 (Unix) php_version: 7.4.28 64bit php_sapi: fpm-fcgi max_input_variables: 1000 time_limit: 240 memory_limit: 128M admin_memory_limit: 256M max_input_time: 60 upload_max_filesize: 32M php_post_max_size: 32M curl_version: 7.79.1 OpenSSL/1.1.1l suhosin: false imagick_availability: true pretty_permalinks: true htaccess_extra_rules: false ### wp-database ### extension: mysqli server_version: 10.3.32-MariaDB client_version: mysqlnd 7.4.28 ### wp-constants ### WP_HOME: undefined WP_SITEURL: undefined WP_CONTENT_DIR: /volume1/web_packages/wordpress/wp-content WP_PLUGIN_DIR: /volume1/web_packages/wordpress/wp-content/plugins WP_MEMORY_LIMIT: 40M WP_MAX_MEMORY_LIMIT: 256M WP_DEBUG: false WP_DEBUG_DISPLAY: true WP_DEBUG_LOG: false SCRIPT_DEBUG: false WP_CACHE: false CONCATENATE_SCRIPTS: undefined COMPRESS_SCRIPTS: undefined COMPRESS_CSS: undefined WP_LOCAL_DEV: undefined DB_CHARSET: utf8 DB_COLLATE: undefined ### wp-filesystem ### wordpress: writable wp-content: writable uploads: writable plugins: writable themes: writable mu-plugins: writable
Vielen Dank für eure Hilfe!
- Dieses Thema wurde geändert vor 2 Jahren von .
- Dieses Thema wurde geändert vor 2 Jahren von . Grund: Codeformatierung korrigiert
Die Seite, für die ich Hilfe brauche: [Anmelden, um den Link zu sehen]
- Das Thema „Einbindung von PHP Skript funktioniert nur in Vorschau korrekt“ ist für neue Antworten geschlossen.