Question

<?php
$search = array('.pdf', '.', '-', '_');
$replace = array('', '/', '</u>- ', ' ');
$query="SELECT  STR_TO_DATE(SUBSTR(`filename`, 1, 10),'%m.%d.%Y') as filedate, `filename`, `filepath`
FROM  `files`  
WHERE `filepath` LIKE 'sites/default/files/news/%' 
ORDER BY filedate DESC
LIMIT 4";
$results = db_query($query);

while ($row = db_fetch_array($results)) {
    echo '<tr>';
    echo '<td><u><a href=http://website.com/sites/default/files/news/'. $row["filename"] . '>' . str_replace($search, $replace, $row["filename"]) . '</a></td><br />';
    echo '</tr>';
}
?>

I have this code on the homepage of my website. It pulls all files in a certain folder that start with a date. Currently, when I add a new file, the query doesn't update, even though when I run the query in PHPmyadmin it works fine.

What's happening to make the query not update itself? Flushing cache's haven't worked for me.

Was it helpful?

Solution

First of all, your not trying to update, your pulling data from the database.

I would suggest you use file_scan_directory.

https://api.drupal.org/api/drupal/includes!file.inc/function/file_scan_directory/7

<?php
$files = file_scan_directory('/sites/default/files/news', '/.*\.pdf$/');
foreach ($files as $file) {
  print $file->filename;
}
?>

Above code is not directly tested.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top