write(file_get_contents($filepath)); try { GSFile::storeFileAsAttachment($file); } catch (Exception $e) { echo "Could not save file {$filepath}, failed with {$e}\n"; } finally { unset($file); } }, ); $manager->flush(); } }