After the file was uploaded successfully, I downloaded it to the local computer, read the content and performed a series of database operations, and then deleted the file, but the deletion failed. And if you delete it immediately next time you come in, the deletion will be successful.
// \File::delete(storage_path(self::SAVE_FILE_NAME)); // 如果写在这里下次再进来删除文件则会成功
// 下载文件到本地
$success = $this->downloadUserFile($data['user_info']);
if ($success) {
$file = new \SplFileObject(storage_path(self::SAVE_FILE_NAME));
$file->setFlags(\SplFileObject::READ_CSV);
foreach($file as $index => $row) {
list($mobile, $userName) = $row;
// 数据库操作
}
// 处理完成后删除(无法成功)
\File::delete(storage_path(self::SAVE_FILE_NAME));
}
PHP中文网2017-05-24 11:35:41
I know the reason. After the file is processed, it needs to be closed before it can be deleted successfully! So set $file=null before deletion