moveUploadedFile example

// Add in our check of the file name length.     $validators['file_validate_name_length'] = [];

    // Call the validation functions specified by this function's caller.     $errors = file_validate($file$validators);
    if (!empty($errors)) {
      throw new FileValidationException('File validation failed', $filename$errors);
    }

    $file->setFileUri($destinationFilename);

    if (!$this->moveUploadedFile($uploadedFile$file->getFileUri())) {
      throw new FileWriteException('File upload error. Could not move uploaded file.');
    }

    // Update the filename with any changes as a result of security or renaming     // due to an existing file.     $file->setFilename($this->fileSystem->basename($file->getFileUri()));

    if ($replace === FileSystemInterface::EXISTS_REPLACE) {
      $existingFile = $this->loadByUri($file->getFileUri());
      if ($existingFile) {
        $file->fid = $existingFile->id();
        
Home | Imprint | This part of the site doesn't use cookies.