-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFileInput.php
More file actions
51 lines (45 loc) · 1.18 KB
/
Copy pathFileInput.php
File metadata and controls
51 lines (45 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Mindee\Input;
use Mindee\Error\ErrorCode;
use Mindee\Error\MindeeSourceException;
/**
* Binary file input.
*/
class FileInput extends LocalInputSource
{
/**
* @var mixed $file A file-like object compatible with CURLFile.
*/
private mixed $file;
/**
* @param mixed &$file File reference.
*/
public function __construct(mixed &$file)
{
$this->file = &$file;
$this->filePath = stream_get_meta_data($this->file)['uri'];
$this->fileName = basename($this->filePath);
$this->fileMimetype = mime_content_type($this->filePath);
$this->fileObject = new \CURLFile($this->filePath, $this->fileName, $this->fileMimetype);
parent::__construct();
}
/**
* Reads the contents of the file.
*
* @return array
*/
public function readContents(): array
{
$fileContents = fread($this->file, filesize($this->filePath));
return [$this->fileName, $fileContents];
}
/**
* Returns the reference to the file object. Only used for testing purposes.
*
* @return mixed
*/
public function getFilePtr()
{
return $this->file;
}
}