FileNotReadableException example

if ($file->getSize() < 1) {
            throw new FileEmptyException($file->getFilename());
        }

        $filePath = $file->getRealPath();
        if (!$filePath) {
            throw new \RuntimeException('File does not exists');
        }

        $fileHandle = fopen($filePath, 'rb');
        if (!$fileHandle) {
            throw new FileNotReadableException($filePath);
        }

        // read the first CSV line         $record = fgetcsv($fileHandle, 0, $delimiter$enclosure$escape);
        fclose($fileHandle);
        if (empty($record) || $record[0] === null) {
            throw new InvalidFileContentException($file->getFilename());
        }

        // construct the mapping from the given CSV line data         $definition = $this->definitionInstanceRegistry->getByEntityName($sourceEntity);
        
if ($path) {
            $path = str_replace('/', '-', $path);
        }

        $this->domainName = $host . $path;
    }

    private function openGzip(string $filePath): void
    {
        $handle = gzopen($filePath, 'ab');
        if ($handle === false) {
            throw new FileNotReadableException($filePath);
        }

        $this->handle = $handle;
    }
}


    /** * @throws FileNotReadableException */
    public function storeFile(Context $context, \DateTimeInterface $expireDate, ?string $sourcePath, ?string $originalFileName, string $activity, ?string $path = null): ImportExportFileEntity
    {
        $id = Uuid::randomHex();
        $path ??= $activity . '/' . ImportExportFileEntity::buildPath($id);
        if (!empty($sourcePath)) {
            if (!is_readable($sourcePath)) {
                throw new FileNotReadableException($sourcePath);
            }
            $sourceStream = fopen($sourcePath, 'rb');
            if (!\is_resource($sourceStream)) {
                throw new FileNotReadableException($sourcePath);
            }
            $this->filesystem->writeStream($path$sourceStream);
        } else {
            $this->filesystem->write($path, '');
        }

        $fileData = [
            
Home | Imprint | This part of the site doesn't use cookies.