Hi, new here and just learning php (and javascript/jquey too a little).
I have some code which pulls a list of jpg files from a directory on the server and then displays them in a drop-down list using a hover event. It is only static at the moment and I have to refresh the page to update the list as new files are added but I am working on this being dynamic and doing it without a page refresh (but that’s another story).
For now I just need help with the display of the files. I don’t want it to display the extension. The file names themselves will never conatin a period or letters j, p or g in them so I figured I could use trim to remove them characters.
this is my php code at the moment. As such it displays the full file name including extension:
$files = array_slice(scandir('upload/'), 2);
rsort($files);
foreach ($files as $file)
echo "<a href='upload/$file'>$file</a>";
Somehow I need to get the following code integrated into the last line:
trim($file, '.jpg');
This is where I am in need of help.
It would look a bit like the below I think (I just need to get the syntax correct).
echo "<a href='upload/$file'>trim($file, '.jpg');</a>";
Can anyone please help?
Many thanks.