src/ImportField.php
public function upload(HTTPRequest $request)
    {
        if ($this->isDisabled() || $this->isReadonly()) {
            return $this->httpError(403);
        }

        // Protect against CSRF on destructive action
        $token = $this->getForm()->getSecurityToken();
        if (!$token->checkRequest($request)) {
            return $this->httpError(400);
        }

        $tmpfile = $request->postVar('Upload');

        // Check if the file has been uploaded into the temporary storage.
        if (!$tmpfile) {
            $return = [
                'error' => _t(
                    'SilverStripe\\AssetAdmin\\Forms\\UploadField.FIELDNOTSET',
                    'File information not found'
                )
            ];
        } else {
            $return = [
                'name' => $tmpfile['name'],
                'size' => $tmpfile['size'],
                'type' => $tmpfile['type'],
                'error' => $tmpfile['error']
            ];
        }

        if (!$return['error']) {
            // Get options for this import.
            $splitHeader = (int)$request->postVar('SplitHeader');
            $keepSource = (bool)$request->postVar('KeepSource');
            $chosenFolderID = (int)$request->postVar('ChosenFolderID');
            $publishPages = (bool)$request->postVar('PublishPages');
            $includeTOC = (bool)$request->postVar('IncludeTOC');

            // Process the document and write the page.
            $preservedDocument = null;
            if ($keepSource) {
                $preservedDocument = $this->preserveSourceDocument($tmpfile, $chosenFolderID);
            }

            $importResult = $this->importFromPOST($tmpfile, $splitHeader, $publishPages, $chosenFolderID);
            if (is_array($importResult) && isset($importResult['error'])) {
                $return['error'] = $importResult['error'];
            } elseif ($includeTOC) {
                $this->writeTOC($publishPages, $keepSource ? $preservedDocument : null);
            }
        }

        $response = HTTPResponse::create(Convert::raw2json([$return]));
        $response->addHeader('Content-Type', 'application/json');
        return $response;
    }
public function upload(HTTPRequest $request)
    {
        if ($this->isDisabled() || $this->isReadonly()) {
            return $this->httpError(403);
        }

        // Protect against CSRF on destructive action
        $token = $this->getForm()->getSecurityToken();
        if (!$token->checkRequest($request)) {
            return $this->httpError(400);
        }

        $tmpfile = $request->postVar('Upload');

        // Check if the file has been uploaded into the temporary storage.
        if (!$tmpfile) {
            $return = [
                'error' => _t(
                    'SilverStripe\\AssetAdmin\\Forms\\UploadField.FIELDNOTSET',
                    'File information not found'
                )
            ];
        } else {
            $return = [
                'name' => $tmpfile['name'],
                'size' => $tmpfile['size'],
                'type' => $tmpfile['type'],
                'error' => $tmpfile['error']
            ];
        }

        if (!$return['error']) {
            // Get options for this import.
            $splitHeader = (int)$request->postVar('SplitHeader');
            $keepSource = (bool)$request->postVar('KeepSource');
            $chosenFolderID = (int)$request->postVar('ChosenFolderID');
            $publishPages = (bool)$request->postVar('PublishPages');
            $includeTOC = (bool)$request->postVar('IncludeTOC');

            // Process the document and write the page.
            $preservedDocument = null;
            if ($keepSource) {
                $preservedDocument = $this->preserveSourceDocument($tmpfile, $chosenFolderID);
            }

            $importResult = $this->importFromPOST($tmpfile, $splitHeader, $publishPages, $chosenFolderID);
            if (is_array($importResult) && isset($importResult['error'])) {
                $return['error'] = $importResult['error'];
            } elseif ($includeTOC) {
                $this->writeTOC($publishPages, $keepSource ? $preservedDocument : null);
            }
        }

        $response = HTTPResponse::create(Convert::raw2json([$return]));
        $response->addHeader('Content-Type', 'application/json');
        return $response;
    }
public function upload ( HTTPRequest $ request ) { if ( $ this -> isDisabled ( ) || $ this -> isReadonly ( ) ) { return $ this -> httpError ( 403 ) ; } // Protect against CSRF on destructive action $ token = $ this -> getForm ( ) -> getSecurityToken ( ) ; if ( ! $ token -> checkRequest ( $ request ) ) { return $ this -> httpError ( 400 ) ; } $ tmpfile = $ request -> postVar ( 'Upload' ) ; // Check if the file has been uploaded into the temporary storage. if ( ! $ tmpfile ) { $ return = [ 'error' => _t ( 'SilverStripe\\AssetAdmin\\Forms\\UploadField.FIELDNOTSET' , 'File information not found' ) ] ; } else { $ return = [ 'name' => $ tmpfile [ 'name' ] , 'size' => $ tmpfile [ 'size' ] , 'type' => $ tmpfile [ 'type' ] , 'error' => $ tmpfile [ 'error' ] ] ; } if ( ! $ return [ 'error' ] ) { // Get options for this import. $ splitHeader = ( int ) $ request -> postVar ( 'SplitHeader' ) ; $ keepSource = ( bool ) $ request -> postVar ( 'KeepSource' ) ; $ chosenFolderID = ( int ) $ request -> postVar ( 'ChosenFolderID' ) ; $ publishPages = ( bool ) $ request -> postVar ( 'PublishPages' ) ; $ includeTOC = ( bool ) $ request -> postVar ( 'IncludeTOC' ) ; // Process the document and write the page. $ preservedDocument = null ; if ( $ keepSource ) { $ preservedDocument = $ this -> preserveSourceDocument ( $ tmpfile , $ chosenFolderID ) ; } $ importResult = $ this -> importFromPOST ( $ tmpfile , $ splitHeader , $ publishPages , $ chosenFolderID ) ; if ( is_array ( $ importResult ) && isset ( $ importResult [ 'error' ] ) ) { $ return [ 'error' ] = $ importResult [ 'error' ] ; } elseif ( $ includeTOC ) { $ this -> writeTOC ( $ publishPages , $ keepSource ? $ preservedDocument : null ) ; } } $ response = HTTPResponse :: create ( Convert :: raw2json ( [ $ return ] ) ) ; $ response -> addHeader ( 'Content-Type' , 'application/json' ) ; return $ response ; }
Process the document immediately upon upload.
Process the document immediately upon upload .