function addImageURL(Product $Product) { if (isset($_FILES['fileImageURL']) && $_FILES['fileImageURL']['size'] > 0) { $errors = array(); $fileName = $_FILES['fileImageURL']['name']; $tmpName = $_FILES['fileImageURL']['tmp_name']; $fileSize = $_FILES['fileImageURL']['size']; $fileType = $_FILES['fileImageURL']['type']; $File = new File($fileName, $tmpName, $fileSize, $fileType); if ($fileSize > 2097152) { $errors[] = 'File phải nhỏ hơn 2 MB'; } if (!$File->isImageType()) { $errors[] = ""; } if (empty($errors) == true) { $logo_Old = trim($Product->getImageURL(), '"'); if (file_exists($logo_Old)) { unlink($logo_Old); } $path = '../assets/images/productImages/' . $Product->getProID(); if (!file_exists($path)) { // neu k ton tai duong dan thu muc cua id nay thi tạo mới File::createDirectory($path); } $type = explode("/", $File->getFileType())[1]; $find = array(" ", "\\", "/", ":", "*", "?", "\"", "<", ">", "|"); $name = File::utf8convert(str_replace($find, '', $Product->getProName())); $pathNew = $path . '/' . $name . "_main." . $type; $File->moveFile($pathNew); $Product->setImageURL($pathNew); $Product->updateImageURL(); } else { // print_r($errors); } if (empty($error)) { // echo "Success"; } } }