@@ -162,7 +162,7 @@ public function javauploadAction()
162
162
163
163
$ parent = $ this ->_getParam ('parent ' );
164
164
$ license = $ this ->_getParam ('license ' );
165
- if (!empty ($ parent ) && !empty ($ license ))
165
+ if (!empty ($ parent ) && !empty ($ license ))
166
166
{
167
167
$ this ->disableView ();
168
168
$ this ->userSession ->JavaUpload ->parent = $ parent ;
@@ -171,45 +171,106 @@ public function javauploadAction()
171
171
}//end java upload
172
172
173
173
174
- /** used to see how much of a file made it to the server during an
175
- * interrupted upload attempt **/
174
+ /**
175
+ * Used to see how much of a file made it to the server during an interrupted upload attempt
176
+ * @param uploadUniqueIdentifier The upload token to check
177
+ */
176
178
function gethttpuploadoffsetAction ()
177
179
{
178
180
$ this ->disableLayout ();
179
181
$ this ->disableView ();
180
182
$ params = $ this ->_getAllParams ();
181
- $ url = $ this ->view ->url ();
182
- $ url = substr ($ url , 0 , strrpos ($ url , '/ ' ));
183
- $ params ['internParameter ' ] = substr ($ url , strrpos ($ url , '/ ' ) + 1 );
184
- $ this ->Component ->Httpupload ->get_http_upload_offset ($ params );
185
- } //end get_http_upload_offset
186
183
187
- /** java upload function, didn't check what it does :-) */
184
+ list ($ userId , , ) = explode ('/ ' , $ params ['uploadUniqueIdentifier ' ]);
185
+ if ($ userId != $ this ->userSession ->Dao ->getUserId ())
186
+ {
187
+ echo '[ERROR]User id does not match upload token user id ' ;
188
+ throw new Zend_Exception ('User id does not match upload token user id ' );
189
+ }
190
+
191
+ $ this ->Component ->Httpupload ->setTmpDirectory ($ this ->getTempDirectory ());
192
+ $ this ->Component ->Httpupload ->setTokenParamName ('uploadUniqueIdentifier ' );
193
+ $ this ->Component ->Httpupload ->getOffset ($ params );
194
+ } //end gethttpuploadoffset
195
+
196
+ /**
197
+ * Get a unique upload token for the java uploader. Must be logged in to do this
198
+ * @param filename The name of the file to be uploaded
199
+ */
188
200
function gethttpuploaduniqueidentifierAction ()
189
201
{
190
202
$ this ->disableLayout ();
191
203
$ this ->disableView ();
192
204
$ params = $ this ->_getAllParams ();
193
- $ this ->Component ->Httpupload ->get_http_upload_unique_identifier ($ params );
205
+
206
+ if (!$ this ->logged )
207
+ {
208
+ throw new Zend_Exception ('You have to be logged in to do that ' );
209
+ }
210
+
211
+ if ($ this ->userSession ->JavaUpload ->parent )
212
+ {
213
+ $ folderId = $ this ->userSession ->JavaUpload ->parent ;
214
+ }
215
+ else
216
+ {
217
+ $ folderId = $ this ->userSession ->Dao ->getPrivatefolderId ();
218
+ }
219
+
220
+ $ this ->Component ->Httpupload ->setTmpDirectory ($ this ->getTempDirectory ());
221
+
222
+ $ dir = $ this ->userSession ->Dao ->getUserId ().'/ ' .$ folderId ;
223
+ try
224
+ {
225
+ $ token = $ this ->Component ->Httpupload ->generateToken ($ params , $ dir );
226
+ echo '[OK] ' .$ token ['token ' ];
227
+ }
228
+ catch (Exception $ e )
229
+ {
230
+ echo '[ERROR] ' .$ e ->getMessage ();
231
+ throw $ e ;
232
+ }
194
233
} //end get_http_upload_unique_identifier
195
234
196
235
197
- /** process java upload*/
236
+ /**
237
+ * Process a java upload
238
+ * @param uploadUniqueIdentifier The upload token (see gethttpuploaduniqueidentifierAction)
239
+ * @param filename The name of the file being uploaded
240
+ * @param length The length of the file being uploaded
241
+ */
198
242
function processjavauploadAction ()
199
243
{
244
+ $ this ->disableLayout ();
245
+ $ this ->disableView ();
200
246
$ params = $ this ->_getAllParams ();
247
+
201
248
if (!$ this ->logged )
202
249
{
203
- echo " [ERROR] You must be logged in to upload " ;
250
+ echo ' [ERROR]You must be logged in to upload ' ;
204
251
throw new Zend_Exception ('You have to be logged in to do that ' );
205
252
}
206
- $ this ->disableLayout ();
207
- $ this ->disableView ();
253
+ list ($ userId , $ parentId , ) = explode ('/ ' , $ params ['uploadUniqueIdentifier ' ]);
254
+ if ($ userId != $ this ->userSession ->Dao ->getUserId ())
255
+ {
256
+ echo '[ERROR]User id does not match upload token user id ' ;
257
+ throw new Zend_Exception ('User id does not match upload token user id ' );
258
+ }
259
+ $ expectedParentId = $ this ->userSession ->JavaUpload ->parent ?
260
+ $ this ->userSession ->JavaUpload ->parent :
261
+ $ this ->userSession ->Dao ->getPrivatefolderId ();
262
+ if ($ parentId != $ expectedParentId )
263
+ {
264
+ echo '[ERROR]You are attempting to upload into the incorrect parent folder ' ;
265
+ throw new Zend_Exception ('You are attempting to upload into the incorrect parent folder ' );
266
+ }
208
267
209
- $ TMP_DIR = BASE_PATH .'/tmp/misc/ ' ;
210
- list ($ filename , $ path , $ length ) = $ this ->Component ->Httpupload ->process_http_upload ($ params );
268
+ $ this ->Component ->Httpupload ->setTmpDirectory ($ this ->getTempDirectory ());
269
+ $ this ->Component ->Httpupload ->setTestingMode (Zend_Registry::get ('configGlobal ' )->environment == 'testing ' );
270
+ $ this ->Component ->Httpupload ->setTokenParamName ('uploadUniqueIdentifier ' );
271
+ $ data = $ this ->Component ->Httpupload ->process ($ params );
211
272
212
- if (!empty ($ path ) && file_exists ($ path ) && $ length > 0 )
273
+ if (!empty ($ data [ ' path ' ] ) && file_exists ($ data [ ' path ' ] ) && $ data [ ' size ' ] > 0 )
213
274
{
214
275
if (isset ($ this ->userSession ->JavaUpload ->parent ))
215
276
{
@@ -230,7 +291,7 @@ function processjavauploadAction()
230
291
231
292
try
232
293
{
233
- $ item = $ this ->Component ->Upload ->createUploadedItem ($ this ->userSession ->Dao , $ filename , $ path , $ parent , $ license );
294
+ $ item = $ this ->Component ->Upload ->createUploadedItem ($ this ->userSession ->Dao , $ data [ ' filename ' ] , $ data [ ' path ' ] , $ parent , $ license, $ data [ ' md5 ' ] );
234
295
}
235
296
catch (Exception $ e )
236
297
{
0 commit comments