%PDF- %GIF98; %PNG;
Server : ApacheSystem : Linux host.digitalbabaji.in 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64 User : addictionfreeind ( 1003) PHP Version : 7.2.34 Disable Function : exec,passthru,shell_exec,system Directory : /home/addictionfreeind/public_html/admin1/vendor/square/square/src/Utils/ |
Upload File : |
<?php
declare(strict_types=1);
namespace Square\Utils;
use SplFileObject;
/**
* Wraps file with mime-type and filename to be sent as part of an HTTP request.
*/
class FileWrapper
{
/**
* @var string
*/
private $realFilePath;
/**
* @var string|null
*/
private $mimeType;
/**
* @var string|null
*/
private $filename;
/**
* Create FileWrapper instance from a file on disk
*/
public static function createFromPath(string $realFilePath, ?string $mimeType = null, ?string $filename = ''): self
{
return new self($realFilePath, $mimeType, $filename);
}
private function __construct(string $realFilePath, ?string $mimeType, ?string $filename)
{
$this->realFilePath = $realFilePath;
$this->mimeType = $mimeType;
$this->filename = $filename;
}
/**
* Get mime-type to be sent with the file
*/
public function getMimeType(): ?string
{
return $this->mimeType;
}
/**
* Get name of the file to be used in the upload data
*/
public function getFilename(): ?string
{
return $this->filename;
}
/**
* Internal method: Do not use directly!
*/
public function createCurlFileInstance(string $defaultMimeType): \CURLFile
{
$mimeType = $this->mimeType ?? $defaultMimeType;
return new \CURLFile($this->realFilePath, $mimeType, $this->filename);
}
/**
* Internal method: Do not use directly!
*/
public function getContent(): ?string
{
$thisFile = new SplFileObject($this->realFilePath);
$content = $thisFile->fread($thisFile->getSize());
return $content === false ? null : $content;
}
}