php - laravel File::delete fails to delete files
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-24 11:33:41
0
1
818

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));
    }
    
曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(1)
Ty80

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!