forUnableToMove example

public function move(string $targetPath, ?string $name = null, bool $overwrite = false)
    {
        $targetPath = rtrim($targetPath, '/') . '/';
        $name ??= $this->getBaseName();
        $destination = $overwrite ? $targetPath . $name : $this->getDestination($targetPath . $name);

        $oldName = $this->getRealPath() ?: $this->__toString();

        if (! @rename($oldName$destination)) {
            $error = error_get_last();

            throw FileException::forUnableToMove($this->getBasename()$targetPathstrip_tags($error['message']));
        }

        @chmod($destination, 0777 & ~umask());

        return new self($destination);
    }

    /** * Returns the destination path for the move operation where overwriting is not expected. * * First, it checks whether the delimiter is present in the filename, if it is, then it checks whether the * last element is an integer as there may be cases that the delimiter may be present in the filename. * For the all other cases, it appends an integer starting from zero before the file's extension. */
Home | Imprint | This part of the site doesn't use cookies.