photos wip - almost there

This commit is contained in:
2025-08-22 00:41:57 -07:00
parent 803e161a9a
commit 9636cc9091
3 changed files with 43 additions and 5 deletions

View File

@@ -71,7 +71,7 @@ class ProductPhotosController extends AppController
$postData['id'] = $uuid;
$baseDir = Configure::readOrFail('CakeProducts.photos.directory');
$product = $productPhotosTable->Products->get($this->request->getData('product_id'));
$path = $baseDir . $product->id;
$path = $product->id;
if ($this->request->getData('product_sku_id')) {
$productSku = $productPhotosTable->ProductSkus->get($this->request->getData('product_sku_id'));
$path .= DS . 'skus' . DS . $productSku->id;
@@ -81,12 +81,13 @@ class ProductPhotosController extends AppController
*/
$photoObject = $this->request->getData('photo');
if (!file_exists($path)) {
if (!mkdir($path, 0777, true)) {
$fullPath = $baseDir . $path;
if (!file_exists($fullPath)) {
if (!mkdir($fullPath, 0777, true)) {
throw new ForbiddenException('Failed to create the required folders. Please check the folder permissions and try again.');
}
}
$destination = $path . DS . $uuid;
$destination = $fullPath . DS . $uuid;
// Existing files with the same name will be replaced.
$photoObject->moveTo($destination);
@@ -157,4 +158,17 @@ class ProductPhotosController extends AppController
return $this->redirect(['action' => 'index']);
}
/**
* @param $id
* @return Response
*/
public function image($id = null)
{
$productPhoto = $this->getTable()->get($id);
$fullPath = Configure::readOrFail('CakeProducts.photos.directory') . $productPhoto->photo_dir . DS . $productPhoto->photo_filename;
return $this->response->withFile($fullPath);
}
}