3 * Implements uploading from previously stored file.
7 * @author Bryan Tong Minh
10 class UploadFromStash
extends UploadBase
{
11 public static function isValidSessionKey( $key, $sessionData ) {
12 return !empty( $key ) &&
13 is_array( $sessionData ) &&
14 isset( $sessionData[$key] ) &&
15 isset( $sessionData[$key]['version'] ) &&
16 $sessionData[$key]['version'] == self
::SESSION_VERSION
;
19 public static function isValidRequest( $request ) {
20 $sessionData = $request->getSessionData( self
::SESSION_KEYNAME
);
21 return self
::isValidSessionKey(
22 $request->getInt( 'wpSessionKey' ),
27 public function initialize( $name, $sessionKey, $sessionData ) {
29 * Confirming a temporarily stashed upload.
30 * We don't want path names to be forged, so we keep
31 * them in the session on the server and just give
32 * an opaque key to the user agent.
35 $this->initializePathInfo( $name,
36 $this->getRealPath ( $sessionData['mTempPath'] ),
37 $sessionData['mFileSize'],
41 $this->mSessionKey
= $sessionKey;
42 $this->mVirtualTempPath
= $sessionData['mTempPath'];
43 $this->mFileProps
= $sessionData['mFileProps'];
46 public function initializeFromRequest( &$request ) {
47 $sessionKey = $request->getInt( 'wpSessionKey' );
48 $sessionData = $request->getSessionData( self
::SESSION_KEYNAME
);
50 $desiredDestName = $request->getText( 'wpDestFile' );
51 if( !$desiredDestName )
52 $desiredDestName = $request->getText( 'wpUploadFile' );
53 return $this->initialize( $desiredDestName, $sessionKey, $sessionData[$sessionKey] );
57 * File has been previously verified so no need to do so again.
59 protected function verifyFile() {
65 * There is no need to stash the image twice
67 public function stashSession( $key = null ) {
68 if ( !empty( $this->mSessionKey
) )
69 return $this->mSessionKey
;
70 return parent
::stashSession();
74 * Remove a temporarily kept file stashed by saveTempUploadedFile().
77 public function unsaveUploadedFile() {
78 $repo = RepoGroup
::singleton()->getLocalRepo();
79 $success = $repo->freeTemp( $this->mVirtualTempPath
);