| Server IP : 74.208.250.37 / Your IP : 216.73.216.114 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ubuntu 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : miferval ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/brainwavemx/app/FileData/ |
Upload File : |
<?php
declare(strict_types=1);
namespace App\DataFile;
use App\DataFile\Data;
use Exception;
class Files
{
private $path;
public function __construct(string $path)
{
if (file_exists($path)) {
$this->path = $path;
} else {
throw new Exception("File do not exist: $path");
}
}
/**
* Generator Function
*/
public function generateFiles(): object
{
foreach (scandir($this->path) as $file) {
if (! in_array($file, ['.', '..'])) {
$extension = $this->getFileExtension($file);
if ($extension == 'jpg' || $extension == 'png') {
yield $file;
}
}
}
}
/**
* File Array
*/
public function getFileArray(): array
{
$fileArray = [];
foreach ($this->generateFiles() as $file) {
array_push($fileArray, $file);
}
return $fileArray;
}
/**
* Sku array
*/
public function getSkuArray(): array
{
$skuArray = [];
foreach ($this->generateFiles() as $file) {
$sku = $this->removeImageExtension($file);
array_push($skuArray, $sku);
}
return $skuArray;
}
public function getFileExtension(string $file): string
{
return pathinfo($file, PATHINFO_EXTENSION);
}
/**
* removeImageExtension
* @param string $file [description]
*/
public function removeImageExtension(string $file): string
{
$file = basename($file, '.jpg');
$file = basename($file, '.png');
return $file;
}
public function backupImage(string $file): void
{
$data = new Data();
$env = $data->env();
$backupPath = $env['BACKUP_IMAGE_PATH'];
rename($this->path . DIRECTORY_SEPARATOR . $file, $backupPath . DIRECTORY_SEPARATOR . $file);
}
}