FIX: no se podia cargar imagenes

This commit is contained in:
2020-05-31 11:59:40 -04:00
parent cb08e0af64
commit 26bd5207f3
3 changed files with 16 additions and 15 deletions

View File

@ -77,20 +77,18 @@ class Producto extends Model {
public function imagenes() {
if ($this->imagenes === null) {
$folder = $this->image_folder;
$this->imagenes = [];
if (!file_exists($folder)) {
$this->imagenes = [];
return [];
return $this->imagenes;
}
if (file_exists($folder)) {
$files = new \DirectoryIterator($folder);
foreach ($files as $file) {
if ($file->isDir()) {
continue;
}
$this->imagenes []= $file->getFilename();
$files = new \DirectoryIterator($folder);
foreach ($files as $file) {
if ($file->isDir()) {
continue;
}
sort($this->imagenes);
$this->imagenes []= $file->getFilename();
}
sort($this->imagenes);
}
return $this->imagenes;
}
@ -112,14 +110,14 @@ class Producto extends Model {
public function deleteImagen(string $file) {
$filename = implode(DIRECTORY_SEPARATOR, [
$this->image_folder,
$imagen
$file
]);
if (!file_exists($filename)) {
return false;
}
$status = unlink($filename);
if (count(scandir($dir)) == 2) {
if (count(scandir($this->image_folder)) == 2) {
rmdir($this->image_folder);
}
return $status;