コード例 #1
0
ファイル: 114.php プロジェクト: PublicityPort/OpenCATS
function update_114($db)
{
    $attachments = $db->query('SELECT * FROM attachment');
    while ($attachment = mysql_fetch_assoc($attachments)) {
        $newFilename = $attachment['stored_filename'];
        for ($i = 0; $i < strlen($newFilename); $i++) {
            if (ord($newFilename[$i]) > 128 || ord($newFilename[$i]) < 32) {
                $newFilename[$i] = '_';
            }
        }
        if (!file_exists('attachments/' . $attachment['directory_name'] . '/' . $attachment['stored_filename']) && is_dir('attachments/' . $attachment['directory_name']) || $newFilename != $attachment['stored_filename']) {
            $filesInDirectory = getAllFilesInDirectory('attachments/' . $attachment['directory_name'] . '/');
            if (count($filesInDirectory) == 1) {
                rename('attachments/' . $attachment['directory_name'] . '/' . $filesInDirectory[0], 'attachments/' . $attachment['directory_name'] . '/' . $newFilename);
                $db->query('UPDATE attachment SET stored_filename = "' . addslashes($newFilename) . '" WHERE attachment_id = ' . $attachment['attachment_id']);
            }
        }
    }
}
コード例 #2
0
function getAllFilesInDirectory($directoryListing, $mpd)
{
    $fileArray = array();
    // Get tracks from directories in this directory first
    for ($index = 0; $index < sizeof($directoryListing['directories']); $index++) {
        $thisDirectory = $directoryListing['directories'][$index];
        $subDir_directoryListing = $mpd->GetDir($thisDirectory);
        $arrayOfFilesInThisDirectory = getAllFilesInDirectory($subDir_directoryListing, $mpd);
        foreach ($arrayOfFilesInThisDirectory as $file) {
            array_push($fileArray, $file);
        }
    }
    // Then get the tracks from this directory
    for ($index = 0; $index < sizeof($directoryListing['files']); $index++) {
        array_push($fileArray, $directoryListing['files'][$index]['file']);
    }
    return $fileArray;
}