@@ -69,10 +69,11 @@ public function checkChunk()
6969
7070 /**
7171 * Save chunk
72+ * @param $additionalUpdateOptions array additional options for the mongo update/upsert operation.
7273 * @return bool
7374 * @throws \Exception if upload size is invalid or some other unexpected error occurred.
7475 */
75- public function saveChunk ()
76+ public function saveChunk ($ additionalUpdateOptions = [] )
7677 {
7778 try {
7879 $ file = $ this ->request ->getFile ();
@@ -91,7 +92,7 @@ public function saveChunk()
9192 throw new \Exception ("Invalid upload! (size: {$ actualChunkSize }) " );
9293 }
9394 $ chunk ['data ' ] = new \MongoBinData ($ data , 0 ); // \MongoBinData::GENERIC is not defined for older mongo drivers
94- $ this ->config ->getGridFs ()->chunks ->findAndModify ($ chunkQuery , $ chunk , [], [ 'upsert ' => true ]);
95+ $ this ->config ->getGridFs ()->chunks ->update ($ chunkQuery , $ chunk , array_merge ([ 'upsert ' => true ], $ additionalUpdateOptions ) );
9596 unlink ($ file ['tmp_name ' ]);
9697
9798 $ this ->ensureIndices ();
@@ -111,15 +112,11 @@ public function saveChunk()
111112 */
112113 public function validateFile ()
113114 {
114- $ totalChunks = $ this ->request ->getTotalChunks ();
115-
116- for ($ i = 1 ; $ i <= $ totalChunks ; $ i ++) {
117- if (!$ this ->chunkExists ($ i )) {
118- return false ;
119- }
120- }
121-
122- return true ;
115+ $ totalChunks = intval ($ this ->request ->getTotalChunks ());
116+ $ storedChunks = $ this ->config ->getGridFs ()->chunks
117+ ->find (['files_id ' => $ this ->getGridFsFile ()['_id ' ]])
118+ ->count ();
119+ return $ totalChunks === $ storedChunks ;
123120 }
124121
125122
0 commit comments