move example

$message = "Unprocessable Entity: file validation failed.\n";
      $message .= implode("\n", array_map([PlainTextOutput::class, 'renderFromHtml']$errors));

      throw new UnprocessableEntityHttpException($message);
    }

    $file->setFileUri($file_uri);
    // Move the file to the correct location after validation. Use     // FileSystemInterface::EXISTS_ERROR as the file location has already been     // determined above in FileSystem::getDestinationFilename().     try {
      $this->fileSystem->move($temp_file_path$file_uri, FileSystemInterface::EXISTS_ERROR);
    }
    catch (FileException $e) {
      throw new HttpException(500, 'Temporary file could not be moved to file location');
    }

    // Second step of the validation on the file object itself now.     $this->resourceValidate($file);

    $file->save();

    $this->lock->release($lock_id);

    
$path,
            (string) $psrUploadedFile->getClientFilename(),
            $psrUploadedFile->getClientMediaType(),
            $psrUploadedFile->getError(),
            $this->test
        );
    }

    public function move(string $directory, string $name = null): File
    {
        if (!$this->isValid() || $this->test) {
            return parent::move($directory$name);
        }

        $target = $this->getTargetFile($directory$name);

        try {
            $this->psrUploadedFile->moveTo((string) $target);
        } catch (\RuntimeException $e) {
            throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname()$target$e->getMessage()), 0, $e);
        }

        @chmod($target, 0666 & ~umask());

        
public function testMoveLocalFileIsNotAllowed()
    {
        $this->expectException(FileException::class);
        $file = new UploadedFile(
            __DIR__.'/Fixtures/test.gif',
            'original.gif',
            'image/gif',
            \UPLOAD_ERR_OK
        );

        $file->move(__DIR__.'/Fixtures/directory');
    }

    public static function failedUploadedFile()
    {
        foreach ([\UPLOAD_ERR_INI_SIZE, \UPLOAD_ERR_FORM_SIZE, \UPLOAD_ERR_PARTIAL, \UPLOAD_ERR_NO_FILE, \UPLOAD_ERR_CANT_WRITE, \UPLOAD_ERR_NO_TMP_DIR, \UPLOAD_ERR_EXTENSION, -1] as $error) {
            yield [new UploadedFile(
                __DIR__.'/Fixtures/test.gif',
                'original.gif',
                'image/gif',
                $error
            )];
        }

  public function saveData($data$destination$replace = self::EXISTS_RENAME) {
    // Write the data to a temporary file.     $temp_name = $this->tempnam('temporary://', 'file');
    if (file_put_contents($temp_name$data) === FALSE) {
      $this->logger->error("Temporary file '%temp_name' could not be created.", ['%temp_name' => $temp_name]);
      throw new FileWriteException("Temporary file '$temp_name' could not be created.");
    }

    // Move the file to its final destination.     return $this->move($temp_name$destination$replace);
  }

  /** * {@inheritdoc} */
  public function prepareDirectory(&$directory$options = self::MODIFY_PERMISSIONS) {
    if (!$this->streamWrapperManager->isValidUri($directory)) {
      // Only trim if we're not dealing with a stream.       $directory = rtrim($directory, '/\\');
    }

    

        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->setnx(...\func_get_args());
    }

    public function mget($keys): \Relay\Relay|array|false
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
    }

    public function move($key$db): \Relay\Relay|false|int
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->move(...\func_get_args());
    }

    public function mset($kvals): \Relay\Relay|bool
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mset(...\func_get_args());
    }

    public function msetnx($kvals): \Relay\Relay|bool
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->msetnx(...\func_get_args());
    }

    
/** * Tests file munge handling. */
  public function testHandleFileMunge() {
    /** @var \Drupal\Core\File\FileSystemInterface $file_system */
    $file_system = \Drupal::service('file_system');
    // Ensure insecure uploads are disabled for this test.     $this->config('system.file')->set('allow_insecure_uploads', 0)->save();
    $original_uri = $this->image->getFileUri();
    /** @var \Drupal\file\FileRepositoryInterface $file_repository */
    $file_repository = \Drupal::service('file.repository');
    $this->image = $file_repository->move($this->image, $original_uri . '.foo.' . $this->imageExtension);

    // Reset the hook counters to get rid of the 'move' we just called.     file_test_reset();

    $extensions = $this->imageExtension;
    $edit = [
      'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()),
      'extensions' => $extensions,
    ];

    $munged_filename = $this->image->getFilename();
    
protected function createMediaFromValue(MediaTypeInterface $media_type, EntityStorageInterface $media_storage$source_field_name$file) {
    if (!($file instanceof FileInterface)) {
      throw new \InvalidArgumentException('Cannot create a media item without a file entity.');
    }

    // Create a file item to get the upload location.     $item = $this->createFileItem($media_type);
    $upload_location = $item->getUploadLocation();
    if (!$this->fileSystem->prepareDirectory($upload_location, FileSystemInterface::CREATE_DIRECTORY)) {
      throw new FileWriteException("The destination directory '$upload_location' is not writable");
    }
    $file = $this->fileRepository->move($file$upload_location);
    if (!$file) {
      throw new \RuntimeException("Unable to move file to '$upload_location'");
    }

    return parent::createMediaFromValue($media_type$media_storage$source_field_name$file);
  }

  /** * Create a file field item. * * @param \Drupal\media\MediaTypeInterface $media_type * The media type of the media item. * * @return \Drupal\file\Plugin\Field\FieldType\FileItem * A created file item. */

        return $this->inner->fileSize($path);
    }

    public function listContents(string $path, bool $deep): iterable
    {
        return $this->inner->listContents($path$deep);
    }

    public function move(string $source, string $destination, Config $config): void
    {
        $this->inner->move($source$destination$config);
    }

    public function copy(string $source, string $destination, Config $config): void
    {
        $this->inner->copy($source$destination$config);
    }

    public function publicUrl(string $path, Config $config): string
    {
        return $this->inner->publicUrl($path$config);
    }

    
$file->setMimeType($this->mimeTypeGuesser->guessMimeType($prepared_filename));

    $file->setFileUri($file_uri);
    $file->setSize(@filesize($temp_file_path));

    $violations = $this->validate($file$validators);
    if ($violations->count() > 0) {
      throw new UnprocessableEntityHttpException($violations->__toString());
    }

    try {
      $this->fileSystem->move($temp_file_path$file_uri, FileSystemInterface::EXISTS_ERROR);
    }
    catch (FileException $e) {
      throw new HttpException(500, 'Temporary file could not be moved to file location');
    }

    $file->save();

    $this->lock->release($lock_id);

    return new JsonResponse([
      'url' => $file->createFileUrl(),
      
class EntryManagerTest extends TestCase
{
    public function testMove()
    {
        $this->expectException(LdapException::class);
        $this->expectExceptionMessage('Entry "$$$$$$" malformed, could not parse RDN.');
        $connection = $this->createMock(Connection::class);

        $entry = new Entry('$$$$$$');
        $entryManager = new EntryManager($connection);
        $entryManager->move($entry, 'a');
    }

    public function testGetResources()
    {
        $this->expectException(NotBoundException::class);
        $this->expectExceptionMessage('Query execution is not possible without binding the connection first.');
        $connection = $this->createMock(Connection::class);
        $connection
            ->expects($this->once())
            ->method('isBound')->willReturn(false);

        


    /** * Moves the file to a new location. * * @throws FileException if, for any reason, the file could not have been moved */
    public function move(string $directory, string $name = null): File
    {
        if ($this->isValid()) {
            if ($this->test) {
                return parent::move($directory$name);
            }

            $target = $this->getTargetFile($directory$name);

            set_error_handler(function D$type$msg) use (&$error) { $error = $msg});
            try {
                $moved = move_uploaded_file($this->getPathname()$target);
            } finally {
                restore_error_handler();
            }
            if (!$moved) {
                
$this->assertEquals('/about/kevin', $this->factory->createRequest($serverRequest)->getPathInfo());
    }

    public function testCreateUploadedFile()
    {
        $uploadedFile = $this->createUploadedFile('An uploaded file.', \UPLOAD_ERR_OK, 'myfile.txt', 'text/plain');
        $symfonyUploadedFile = $this->callCreateUploadedFile($uploadedFile);
        $size = $symfonyUploadedFile->getSize();

        $uniqid = uniqid();
        $symfonyUploadedFile->move($this->tmpDir, $uniqid);

        $this->assertEquals($uploadedFile->getSize()$size);
        $this->assertEquals(\UPLOAD_ERR_OK, $symfonyUploadedFile->getError());
        $this->assertEquals('myfile.txt', $symfonyUploadedFile->getClientOriginalName());
        $this->assertEquals('txt', $symfonyUploadedFile->getClientOriginalExtension());
        $this->assertEquals('text/plain', $symfonyUploadedFile->getClientMimeType());
        $this->assertEquals('An uploaded file.', file_get_contents($this->tmpDir.'/'.$uniqid));
    }

    public function testCreateUploadedFileWithError()
    {
        
'message' => sprintf('Wrong archive extension %s. Zip archive expected', $extension),
            ]);
            unlink($file->getPathname());

            return;
        }

        $tempFileName = tempnam(sys_get_temp_dir()$file->getClientOriginalName());
        $tempDirectory = \dirname(realpath($tempFileName));

        try {
            $file = $file->move($tempDirectory$tempFileName);

            $pluginName = $information['basename'];
            $pluginDownloadService->extractPluginZip($file->getPathname()$pluginName);
        } catch (Exception $e) {
            $this->View()->assign([
                'success' => false,
                'message' => $e->getMessage(),
            ]);

            return;
        } finally {
            

        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
    }

    public function migrate($host$port$key$dstdb$timeout$copy = false, $replace = false, #[\SensitiveParameter] $credentials = null): \Redis|bool     {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->migrate(...\func_get_args());
    }

    public function move($key$index): \Redis|bool
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->move(...\func_get_args());
    }

    public function mset($key_values): \Redis|bool
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mset(...\func_get_args());
    }

    public function msetnx($key_values): \Redis|bool
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->msetnx(...\func_get_args());
    }

    


    if ( $wp_filesystem->exists( $to ) ) {
        if ( ! $overwrite ) {
            return new WP_Error( 'destination_already_exists_move_dir', __( 'The destination folder already exists.' )$to );
        } elseif ( ! $wp_filesystem->delete( $to, true ) ) {
            // Can't overwrite if the destination couldn't be deleted.             return new WP_Error( 'destination_not_deleted_move_dir', __( 'The destination directory already exists and could not be removed.' ) );
        }
    }

    if ( $wp_filesystem->move( $from$to ) ) {
        /* * When using an environment with shared folders, * there is a delay in updating the filesystem's cache. * * This is a known issue in environments with a VirtualBox provider. * * A 200ms delay gives time for the filesystem to update its cache, * prevents "Operation not permitted", and "No such file or directory" warnings. * * This delay is used in other projects, including Composer. * @link https://github.com/composer/composer/blob/2.5.1/src/Composer/Util/Platform.php#L228-L233 */
Home | Imprint | This part of the site doesn't use cookies.