mysql - Updating a database info when a file is updated in PHP -
i have database(mysql) table stores link of files can downloaded , contains last time these files updated.
i time values(timestamps) in database table change whenever run code update files in filemanager in cpanel.
how do in php? tried searching, no avail. need guidance on this.
so far have done create interface can insert files in database using sb admin v2.0. takes care of updating timevalue. however, not need interface because run code update files.
so looking @ how last modified time of file using php?
if updating files system via external script (not php) need "listen" files. so, use cron job run (pseudo) code.
$files = array( 'file1.txt' => array('timestamp' => '12345678'), 'file2.txt' => array('timestamp' => '12346879'), ); $target = '/uploads'; $weeds = array('.', '..'); $uploadedfiles = array_diff(scandir($target), $weeds); foreach ($uploadedfiles $filename) { if (isset($files[$filename])) { if ($files[$filename]['timestamp'] < filemtime($filename)) { $db->update('update files set timestamp = :timestamp file_name = :filename'); $db->params = array_merge($db->params, array(':filename' => $filename, ':timestamp' => $files[$filename]['timestamp'])); } } else { $db->insert(getfileinfo($filename)); } }
Comments
Post a Comment