File tree Expand file tree Collapse file tree 3 files changed +13
-19
lines changed Expand file tree Collapse file tree 3 files changed +13
-19
lines changed Original file line number Diff line number Diff line change 19
19
use function getenv ;
20
20
use function strlen ;
21
21
22
- use const PHP_EOL ;
23
-
24
22
require __DIR__ . '/../vendor/autoload.php ' ;
25
23
26
24
$ client = new Client (getenv ('MONGODB_URI ' ) ?: 'mongodb://127.0.0.1/ ' );
31
29
$ stream = $ bucket ->openUploadStream ('hello.txt ' );
32
30
33
31
for ($ i = 0 ; $ i < 1_000_000 ; $ i ++) {
34
- fwrite ($ stream , 'Hello line ' . $ i . PHP_EOL );
32
+ fwrite ($ stream , 'Hello line ' . $ i . "\n" );
35
33
}
36
34
37
35
// Last data are flushed to the server when the stream is closed
46
44
$ size += strlen ($ data );
47
45
}
48
46
49
- echo 'Read a total of ' . $ size . ' bytes ' . PHP_EOL ;
47
+ echo 'Read a total of ' . $ size . ' bytes ' . "\n" ;
50
48
51
49
// Retrieve the file ID to delete it
52
50
$ id = $ bucket ->getFileIdForStream ($ stream );
53
51
assert ($ id instanceof ObjectId);
54
52
$ bucket ->delete ($ id );
55
53
56
- echo 'Deleted file with ID: ' . $ id . PHP_EOL ;
54
+ echo 'Deleted file with ID: ' . $ id . "\n" ;
Original file line number Diff line number Diff line change 18
18
use function getenv ;
19
19
use function stream_context_create ;
20
20
21
- use const PHP_EOL ;
22
-
23
21
require __DIR__ . '/../vendor/autoload.php ' ;
24
22
25
23
$ client = new Client (getenv ('MONGODB_URI ' ) ?: 'mongodb://127.0.0.1/ ' );
31
29
32
30
echo 'File exists: ' ;
33
31
echo file_exists ('gridfs://mybucket/hello.txt ' ) ? 'yes ' : 'no ' ;
34
- echo PHP_EOL ;
32
+ echo "\n" ;
35
33
36
34
echo 'Writing file ' ;
37
35
file_put_contents ('gridfs://mybucket/hello.txt ' , 'Hello, GridFS! ' );
38
- echo PHP_EOL ;
36
+ echo "\n" ;
39
37
40
38
echo 'File exists: ' ;
41
39
echo file_exists ('gridfs://mybucket/hello.txt ' ) ? 'yes ' : 'no ' ;
42
- echo PHP_EOL ;
40
+ echo "\n" ;
43
41
44
42
echo 'Reading file: ' ;
45
43
echo file_get_contents ('gridfs://mybucket/hello.txt ' );
46
- echo PHP_EOL ;
44
+ echo "\n" ;
47
45
48
46
echo 'Writing new version of the file ' ;
49
47
file_put_contents ('gridfs://mybucket/hello.txt ' , 'Hello, GridFS! (v2) ' );
50
- echo PHP_EOL ;
48
+ echo "\n" ;
51
49
52
50
echo 'Reading new version of the file: ' ;
53
51
echo file_get_contents ('gridfs://mybucket/hello.txt ' );
54
- echo PHP_EOL ;
52
+ echo "\n" ;
55
53
56
54
echo 'Reading previous version of the file: ' ;
57
55
$ context = stream_context_create (['gridfs ' => ['revision ' => -2 ]]);
58
56
echo file_get_contents ('gridfs://mybucket/hello.txt ' , false , $ context );
59
- echo PHP_EOL ;
57
+ echo "\n" ;
Original file line number Diff line number Diff line change 19
19
use function rewind ;
20
20
use function stream_get_contents ;
21
21
22
- use const PHP_EOL ;
23
-
24
22
require __DIR__ . '/../vendor/autoload.php ' ;
25
23
26
24
$ client = new Client (getenv ('MONGODB_URI ' ) ?: 'mongodb://127.0.0.1/ ' );
35
33
// Upload to GridFS from the stream
36
34
$ id = $ gridfs ->uploadFromStream ('hello.txt ' , $ stream );
37
35
assert ($ id instanceof ObjectId);
38
- echo 'Inserted file with ID: ' . $ id . PHP_EOL ;
36
+ echo 'Inserted file with ID: ' , $ id, "\n" ;
39
37
fclose ($ stream );
40
38
41
39
// Download the file and print the contents directly to an in-memory stream, chunk by chunk
42
40
$ stream = fopen ('php://temp ' , 'w+ ' );
43
41
$ gridfs ->downloadToStreamByName ('hello.txt ' , $ stream );
44
42
rewind ($ stream );
45
- echo 'File contents: ' . stream_get_contents ($ stream ) . PHP_EOL ;
43
+ echo 'File contents: ' , stream_get_contents ($ stream ), "\n" ;
46
44
47
45
// Delete the file
48
46
$ gridfs ->delete ($ id );
49
47
50
- echo 'Deleted file with ID: ' . $ id . PHP_EOL ;
48
+ echo 'Deleted file with ID: ' , $ id, "\n" ;
You can’t perform that action at this time.
0 commit comments