PHPSpreadsheet 不会让我删除文件,HTTP/Apache 不会停止使用它们

PHPSpreadsheet won't let me delete files, HTTP/Apache won't stop using them

提问人:Lucas Ferreira 提问时间:11/17/2023 最后编辑:Lucas Ferreira 更新时间:11/17/2023 访问量:23

问:

我正在开发一个应用程序,该应用程序对MySQL数据库进行了请求,并且可以直接下载到xlsx中。 当申请太大(2000 行 +)时,它会一点一点地添加行,即 200 x 200。当请求的所有行都定位好后,文件将更改到目录中的文件夹(保存在不同的文件夹中,不久后删除原始文件)。

        //Retrieving the file
        $this->spreadsheet = IOFactory::load($this->fileWay);
        $this->worksheet = $this->spreadsheet->getActiveSheet();

        $rows =  $this->worksheet->getHighestRow();

        $newData = $this->req->getData($rows); //Retrieving the original request data to add it after
        $this->addRows($newData, $rows); //Adding the request rows (library job)
        $this->defineCompletion(); //Verifying and defining if the sheet is complete or not
        $this->fileSize = filesize($this->fileWay);

        //Updating it into the db
        $updater = new Updater();
        $updater->sheet = $this;

        if ($this->finished) {
            $folder = 'realized';
            $updater->finishFile();
            $updater->updateWholeRow('solicitado', 'realizado'); //Change the db table

            //Here i try to disconnect the file from the server, doesn't work
            gc_collect_cycles();
            $this->spreadsheet->disconnectWorksheets();
            unset($this->spreadsheet);

            //Can't rename or even unlink the file
            if (rename($this->fileWay, "{$GLOBALS['prePath']}files/realized/{$this->fileName}")) {
                echo "arquivo movido";
            }

这就是它返回的内容。我正在使用 Wampserver,但也使用了 Xampp,结果是一样的:

Warning: rename({file and it's directory}): The file is already being used by another process (code: 32) in C:\wamp64\www\NewPreFatura\classes\Sheet.php on line <i>61</i></th></tr>

我尝试了上面的所有这些方法。当我关闭服务器时,我可以轻松地自己删除目录中的文件。

此函数与 Ajax 一起运行。5s间隔。

php ajax phpspreadsheet

评论


答: 暂无答案