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'] == UploadBase
::SESSION_VERSION
;
19 public static function isValidRequest( $request ) {
20 $sessionData = $request->getSessionData( UploadBase
::SESSION_KEYNAME
);
21 return self
::isValidSessionKey(
22 $request->getText( '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'];
44 $this->mSourceType
= isset( $sessionData['mSourceType'] ) ?
45 $sessionData['mSourceType'] : null;
48 public function initializeFromRequest( &$request ) {
49 $sessionKey = $request->getText( 'wpSessionKey' );
50 $sessionData = $request->getSessionData( UploadBase
::SESSION_KEYNAME
);
52 $desiredDestName = $request->getText( 'wpDestFile' );
53 if( !$desiredDestName )
54 $desiredDestName = $request->getText( 'wpUploadFile' );
55 return $this->initialize( $desiredDestName, $sessionKey, $sessionData[$sessionKey] );
58 public function getSourceType() {
59 return $this->mSourceType
;
63 * File has been previously verified so no need to do so again.
65 protected function verifyFile() {
71 * There is no need to stash the image twice
73 public function stashSession( $key = null ) {
74 if ( !empty( $this->mSessionKey
) )
75 return $this->mSessionKey
;
76 return parent
::stashSession();
80 * Remove a temporarily kept file stashed by saveTempUploadedFile().
83 public function unsaveUploadedFile() {
84 $repo = RepoGroup
::singleton()->getLocalRepo();
85 $success = $repo->freeTemp( $this->mVirtualTempPath
);