2

这里有点奇怪的问题。我最近开始在一个我最初没有建立的网站上进行维护。Drupal 站点有一堆带有音频文件字段的节点,以及一个播放它们的 jQuery 播放器。在很多节点上播放器没有加载,我意识到这是因为当我编辑节点时文件被报告为 0 字节。我不确定这是为什么。起初我认为这可能是文件权限的问题,但我不认为是这样,因为权限对我来说很好。为了解决这个问题,我所要做的就是重新上传文件。问题是这些文件有数百个,如果可能的话,我想通过进行一次更新来修复它。

4

2 回答 2

4

Here is a working version of Terry's pseudocode for Drupal 7.

$fids = db_query('SELECT fid FROM {file_managed} WHERE filesize = 0')->fetchCol();

foreach(file_load_multiple($fids) as $file) {
  // Get full path to file.
  $target = drupal_realpath($file->uri);
  // If the file does not exist try the next file.
  if (!file_exists($target)) {
    echo "File $file->uri does not exist." .PHP_EOL;
    continue;
  }
  // Find and store size of file
    $file->filesize = filesize($target);
    // Size of file is
    if ($file->filesize > 0) {
      file_save($file);
    }
    else {
      echo "Size of $file->uri is still zero." . PHP_EOL;
    }
}

Run it with drush:

drush php-script fix-file-sizes.php
于 2013-10-22T00:55:35.010 回答
1

我们遇到了同样的问题:数据库中有很多 0 字节的文件。我们所做的看起来像这样:

function update_my_filesizes() {
    $fileIDs = db_query('SELECT fid FROM {file_managed) WHERE filesize = 0')->fetchCol();

    foreach(file_load_multiple($fids) as $file) {
        // determine size of file
        $filesize = SIZE_OF_THE_FILE; (pseudocode, we had to use filesize())
        $file->filesize = $filesize;

        if($file->filesize > 0) {        
            file_save($file);
        } else {
            echo "Filesize for file <filename here> is still 0 :(";
        }
    }
}
于 2012-08-22T18:58:40.803 回答