concrete/src/File/Importer.php
public function importIncomingFile($filename, $fr = false)
    {
        $fh = $this->app->make('helper/validation/file');
        if (!$fh->extension($filename)) {
            return self::E_FILE_INVALID_EXTENSION;
        }
        $incoming = $this->app->make(Incoming::class);
        $incomingStorageLocation = $incoming->getIncomingStorageLocation();
        $incomingFilesystem = $incomingStorageLocation->getFileSystemObject();
        $incomingPath = $incoming->getIncomingPath();
        if (!$incomingFilesystem->has($incomingPath . '/' . $filename)) {
            return self::E_FILE_INVALID;
        }
        if ($fr instanceof FileEntity) {
            $destinationStorageLocation = $fr->getFileStorageLocationObject();
        } else {
            $destinationStorageLocation = $this->app->make(StorageLocationFactory::class)->fetchDefault();
        }
        $destinationFilesystem = $destinationStorageLocation->getFileSystemObject();
        $prefix = $this->generatePrefix();
        $fi = $this->app->make('helper/file');
        $sanitizedFilename = $fi->sanitize($filename);
        $cf = $this->app->make('helper/concrete/file');
        $destinationPath = $cf->prefix($prefix, $sanitizedFilename);
        try {
            $stream = $incomingFilesystem->readStream($incomingPath . '/' . $filename);
        } catch (Exception $x) {
            $stream = false;
        }
        if ($stream === false) {
            return self::E_FILE_INVALID;
        }
        try {
            $wrote = $destinationFilesystem->writeStream($destinationPath, $stream);
        } catch (Exception $x) {
            $wrote = false;
        }
        @fclose($stream);
        if ($wrote === false) {
            return self::E_FILE_UNABLE_TO_STORE;
        }
        if (!($fr instanceof FileEntity)) {
            // we have to create a new file object for this file version
            $fv = File::add($sanitizedFilename, $prefix, ['fvTitle' => $filename], $destinationStorageLocation, $fr);
            $fv->refreshAttributes($this->rescanThumbnailsOnImport);

            foreach ($this->importProcessors as $processor) {
                if ($processor->shouldProcess($fv)) {
                    $processor->process($fv);
                }
            }
        } else {
            // We get a new version to modify
            $fv = $fr->getVersionToModify(true);
            $fv->updateFile($sanitizedFilename, $prefix);
            $fv->refreshAttributes($this->rescanThumbnailsOnImport);
        }

        return $fv;
    }
public function importIncomingFile($filename, $fr = false)
    {
        $fh = $this->app->make('helper/validation/file');
        if (!$fh->extension($filename)) {
            return self::E_FILE_INVALID_EXTENSION;
        }
        $incoming = $this->app->make(Incoming::class);
        $incomingStorageLocation = $incoming->getIncomingStorageLocation();
        $incomingFilesystem = $incomingStorageLocation->getFileSystemObject();
        $incomingPath = $incoming->getIncomingPath();
        if (!$incomingFilesystem->has($incomingPath . '/' . $filename)) {
            return self::E_FILE_INVALID;
        }
        if ($fr instanceof FileEntity) {
            $destinationStorageLocation = $fr->getFileStorageLocationObject();
        } else {
            $destinationStorageLocation = $this->app->make(StorageLocationFactory::class)->fetchDefault();
        }
        $destinationFilesystem = $destinationStorageLocation->getFileSystemObject();
        $prefix = $this->generatePrefix();
        $fi = $this->app->make('helper/file');
        $sanitizedFilename = $fi->sanitize($filename);
        $cf = $this->app->make('helper/concrete/file');
        $destinationPath = $cf->prefix($prefix, $sanitizedFilename);
        try {
            $stream = $incomingFilesystem->readStream($incomingPath . '/' . $filename);
        } catch (Exception $x) {
            $stream = false;
        }
        if ($stream === false) {
            return self::E_FILE_INVALID;
        }
        try {
            $wrote = $destinationFilesystem->writeStream($destinationPath, $stream);
        } catch (Exception $x) {
            $wrote = false;
        }
        @fclose($stream);
        if ($wrote === false) {
            return self::E_FILE_UNABLE_TO_STORE;
        }
        if (!($fr instanceof FileEntity)) {
            // we have to create a new file object for this file version
            $fv = File::add($sanitizedFilename, $prefix, ['fvTitle' => $filename], $destinationStorageLocation, $fr);
            $fv->refreshAttributes($this->rescanThumbnailsOnImport);

            foreach ($this->importProcessors as $processor) {
                if ($processor->shouldProcess($fv)) {
                    $processor->process($fv);
                }
            }
        } else {
            // We get a new version to modify
            $fv = $fr->getVersionToModify(true);
            $fv->updateFile($sanitizedFilename, $prefix);
            $fv->refreshAttributes($this->rescanThumbnailsOnImport);
        }

        return $fv;
    }
public function importIncomingFile ( $ filename , $ fr = false ) { $ fh = $ this -> app -> make ( 'helper/validation/file' ) ; if ( ! $ fh -> extension ( $ filename ) ) { return self :: E_FILE_INVALID_EXTENSION ; } $ incoming = $ this -> app -> make ( Incoming :: class ) ; $ incomingStorageLocation = $ incoming -> getIncomingStorageLocation ( ) ; $ incomingFilesystem = $ incomingStorageLocation -> getFileSystemObject ( ) ; $ incomingPath = $ incoming -> getIncomingPath ( ) ; if ( ! $ incomingFilesystem -> has ( $ incomingPath . '/' . $ filename ) ) { return self :: E_FILE_INVALID ; } if ( $ fr instanceof FileEntity ) { $ destinationStorageLocation = $ fr -> getFileStorageLocationObject ( ) ; } else { $ destinationStorageLocation = $ this -> app -> make ( StorageLocationFactory :: class ) -> fetchDefault ( ) ; } $ destinationFilesystem = $ destinationStorageLocation -> getFileSystemObject ( ) ; $ prefix = $ this -> generatePrefix ( ) ; $ fi = $ this -> app -> make ( 'helper/file' ) ; $ sanitizedFilename = $ fi -> sanitize ( $ filename ) ; $ cf = $ this -> app -> make ( 'helper/concrete/file' ) ; $ destinationPath = $ cf -> prefix ( $ prefix , $ sanitizedFilename ) ; try { $ stream = $ incomingFilesystem -> readStream ( $ incomingPath . '/' . $ filename ) ; } catch ( Exception $ x ) { $ stream = false ; } if ( $ stream === false ) { return self :: E_FILE_INVALID ; } try { $ wrote = $ destinationFilesystem -> writeStream ( $ destinationPath , $ stream ) ; } catch ( Exception $ x ) { $ wrote = false ; } @ fclose ( $ stream ) ; if ( $ wrote === false ) { return self :: E_FILE_UNABLE_TO_STORE ; } if ( ! ( $ fr instanceof FileEntity ) ) { // we have to create a new file object for this file version $ fv = File :: add ( $ sanitizedFilename , $ prefix , [ 'fvTitle' => $ filename ] , $ destinationStorageLocation , $ fr ) ; $ fv -> refreshAttributes ( $ this -> rescanThumbnailsOnImport ) ; foreach ( $ this -> importProcessors as $ processor ) { if ( $ processor -> shouldProcess ( $ fv ) ) { $ processor -> process ( $ fv ) ; } } } else { // We get a new version to modify $ fv = $ fr -> getVersionToModify ( true ) ; $ fv -> updateFile ( $ sanitizedFilename , $ prefix ) ; $ fv -> refreshAttributes ( $ this -> rescanThumbnailsOnImport ) ; } return $ fv ; }
Import a file in the default file storage location's incoming directory.

@param string $filename the name of the file in the incoming directory
@param \Concrete\Core\Entity\File\File|\Concrete\Core\Tree\Node\Type\FileFolder|null|false $fr If it's a File entity we assign the newly imported FileVersion object to that File. If it's a FileFolder entiity we'll create a new File in that folder (otherwise the new File will be created in the root folder).

@return \Concrete\Core\Entity\File\Version|int the imported file version (or an error code in case of problems)
Import a file in the default file storage location s incoming directory .