File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change 108
108
// end-bulk-write
109
109
110
110
// Creates a GridFS bucket or references an existing one
111
- // start-gridfs
111
+ // start-gridfs-bucket
112
112
$ bucket = $ client ->selectDatabase ('<database name> ' )->selectGridFSBucket ();
113
- // end-gridfs
113
+ // end-gridfs-bucket
114
+
115
+ // Stores a file in a GridFS bucket and writes data to the file
116
+ // start-gridfs-upload
117
+ $ stream = $ bucket ->openUploadStream ('<file name> ' );
118
+ fwrite ($ stream , '<data> ' );
119
+ fclose ($ stream );
120
+ // end-gridfs-upload
Original file line number Diff line number Diff line change @@ -171,17 +171,32 @@ operation:
171
171
To learn more about the ``MongoDB\Collection::bulkWrite()`` method, see the
172
172
:ref:`Bulk Write <php-bulk-write>` guide.
173
173
174
- Store Large Files
175
- -----------------
174
+ Create a GridFS Bucket
175
+ ----------------------
176
176
177
177
The following code shows how to create or reference a GridFS bucket, which
178
178
you can write large files to:
179
179
180
180
.. literalinclude:: /includes/usage-examples/write-code-examples.php
181
- :start-after: start-gridfs
182
- :end-before: end-gridfs
181
+ :start-after: start-gridfs-bucket
182
+ :end-before: end-gridfs-bucket
183
183
:language: php
184
184
:dedent:
185
185
186
186
To learn more about the ``MongoDB\Database::selectGridFSBucket()`` method, see the
187
187
:ref:`Store Large Files <php-gridfs>` guide.
188
+
189
+ Store GridFS Files
190
+ ------------------
191
+
192
+ The following code shows how to store files in a GridFS bucket by
193
+ creating an upload stream:
194
+
195
+ .. literalinclude:: /includes/usage-examples/write-code-examples.php
196
+ :start-after: start-gridfs-upload
197
+ :end-before: end-gridfs-upload
198
+ :language: php
199
+ :dedent:
200
+
201
+ To learn more about the ``MongoDB\GridFS\Bucket::openUploadStream()`` method, see the
202
+ :ref:`Store Large Files <php-gridfs>` guide.
You can’t perform that action at this time.
0 commit comments