I need to stop Joomla from converting PHP code to a comment (or otherwise disabling it).
I copied a working page with a basic [directory listing] function, and the duplicate wouldn't work.
I am nearly positive Joomla is "intelligently" modifying the PHP to disable it--how can I stop this?
X/Y Problem: A working extension to list directory contents would sidestep this issue, because that's really what I need--though I'd prefer to also learn what I'm doing wrong.
TL;DR
I periodically provide updates for a site (Joomla 2.5) I neither own nor host. I've recommended we update or rebuild it, so far a non-option.
I don't really know much PHP. However the below code polls a given directory and links the files. The customer has backend access and can quickly distribute information via this page, uploading PDF files as required and removing the obsolete ones. Simple for the customer and works great.
Yesterday she requested a new page for a different category of information.
I created a separate directory for the new page (Turnover) and updated the copied code to reflect this. The original page (Output) worked fine, but the duplicate page was blank except for title. I took a step back but not even the unmodified copy would work on the new page--though it still worked on the old.
Before realizing the PHP was not even being executed, I verified that
- The articles are identical except by title and index number
- Permissions on the new directory match the original AFAICT
- It's not file, filename, or size (new file immediately worked in the old directory)
- Also created a second duplicate page to rule out human error
Since one page works and another doesn't, it's clearly not an incompatibility between Joomla and PHP versions, and most likely not a server misconfiguration.
The page source on the broken page show the PHP as a comment; the working page served working links:
file1
file2
file3
After extended troubleshooting, I altered only the title of the original page--and it subsequently failed. I now have two pages that won't work, meaning the customer will need to upload files and then wait until I can log in and manually create individual links. Then she'll wait again when I remove old ones.
I don't have shell access, nor to backups, if they even exist. I learned last night that Joomla lacks a revision history. I normally use Wordpress, and this hasn't convinced me to switch. :,/
I suspect the issue is with Joomla and not the code itself. Code examples I've seen begin with <?php
(and not <!--?php
), but my assumption that this is the sole issue could be wrong. When I manually remove those three characters, the code is simply converted to text as part of the page.
The code below is exactly how I first saw it in the HTML editor (without the HTML editor I don't even see the PHP at all). Joomla adds the paragraph tags automatically and converts <b> tags to <strong>. (I checked page source of both pages before and after I broke the original page).
<p><strong>Output</strong></p>
<!--?php
//path to directory to scan
$directory = "images/download/output/";
$files = glob($directory . "*.pdf");
array_multisort(array_map( 'filemtime', $files ),SORT_NUMERIC,SORT_DESC,$files);
//print each file name
foreach($files as $f) {
$path_parts = pathinfo($f);
echo '<p><a href="'.$f.'">'.$path_parts['filename'].'</a></p>';
}
?-->
<p> </p>
(thanks to the mod who migrated for me--I should've checked to see if there was a Joomla stack)
With a busy weekend already underway, fixing this is pretty important--thanks for any help/advice offered. I figured this should take fifteen or twenty minutes--but I've burned hours on it.