function imageUpload($argFILES, $argVarDirLocation, $varThumbnailWidth = '', $varThumbnailHeight = '', $varMediumWidth = '', $varMediumHeight = '') { $objUpload = new upload(); $objCore = new Core(); $objUpload->setMaxSize(); $objUpload->setDirectory($argVarDirLocation); $varIsImage = $objUpload->IsImageValid($argFILES['type']); if ($varIsImage) { $varImageExists = 'yes'; } else { $varImageExists = 'no'; } if ($varImageExists == 'no') { $objCore->setErrorMsg(IMAGE_TYPE_ERROR); return false; } if ($varImageExists == 'yes') { $objUpload->setTmpName($argFILES['tmp_name']); if ($objUpload->userTmpName) { $objUpload->setFileSize($argFILES['size']); $objUpload->setFileType($argFILES['type']); $varRandomNumber = $this->generateRandomKey(); $fileName = $varRandomNumber . '_' . strtolower($argFILES['name']); $fileName = str_replace(' ', '_', $fileName); $objUpload->setFileName($fileName); $objUpload->startCopy(); if ($objUpload->isError()) { $thumbnailName1 = '_thumb'; $objUpload->setThumbnailName($thumbnailName1); $objUpload->createThumbnail(); if ($varThumbnailWidth == '' && $varThumbnailHeight == '') { $objUpload->setThumbnailSize(); } else { $objUpload->setThumbnailSize($varThumbnailWidth, $varThumbnailHeight); } $varFileName = $objUpload->userFileName; $varExt = substr(strrchr($varFileName, "."), 1); $varThumbFileNameNoExt = substr($varFileName, 0, -(strlen($varExt) + 1)); $varThumbFileName = $varThumbFileNameNoExt . 'thumb.' . $varExt; $thumbnailName1 = ''; $objUpload->setThumbnailName($thumbnailName1); $objUpload->createThumbnail(); if ($varMediumWidth == '' && $varMediumHeight == '') { $objUpload->setThumbnailSize(); } else { $objUpload->setThumbnailSize($varMediumWidth, $varMediumHeight); } return $varFileName; } else { $objCore->setErrorMsg(ERROR_ON_UPLOAD); return false; } } } }
function imageUpload($argFILES, $argVarDirLocation, $varThumbnailWidth = '', $varThumbnailHeight = '', $varMediumWidth = '', $varMediumHeight = '') { //$argVarProductName = $argFILES['name']; $objUpload = new upload(); $objCore = new Core(); $objUpload->setMaxSize(); // Set Directory $objUpload->setDirectory($argVarDirLocation); $varIsImage = $objUpload->IsImageValid($argFILES['type']); if ($varIsImage) { $varImageExists = 'yes'; } else { $varImageExists = 'no'; } if ($varImageExists == 'no') { $objCore->setErrorMsg(IMAGE_TYPE_ERROR); return false; } if ($varImageExists == 'yes') { $objUpload->setTmpName($argFILES['tmp_name']); //echo $objUpload->userTmpName;die; if ($objUpload->userTmpName) { // Set file size $objUpload->setFileSize($argFILES['size']); // Set File Type $objUpload->setFileType($argFILES['type']); // Set File Name $varRandomNumber = $this->generateRandomKey(); $fileName = $varRandomNumber . '_' . strtolower($argFILES['name']); //replace space with an underscore $fileName = str_replace(' ', '_', $fileName); $objUpload->setFileName($fileName); // Start Copy Process $objUpload->startCopy(); // If there is error write the error message if ($objUpload->isError()) { // Set a thumbnail name $thumbnailName1 = '_thumb'; $objUpload->setThumbnailName($thumbnailName1); // create thumbnail $objUpload->createThumbnail(); // change thumbnail size if ($varThumbnailWidth == '' && $varThumbnailHeight == '') { $objUpload->setThumbnailSize(); } else { $objUpload->setThumbnailSize($varThumbnailWidth, $varThumbnailHeight); } //Get file name from the class public variable $varFileName = $objUpload->userFileName; //Get file extention $varExt = substr(strrchr($varFileName, "."), 1); $varThumbFileNameNoExt = substr($varFileName, 0, -(strlen($varExt) + 1)); //Create thumb file name $varThumbFileName = $varThumbFileNameNoExt . 'thumb.' . $varExt; //--------------------FOR MEDIUM SIZE IMAGE-------------------------- // Set a MIDIUM name $thumbnailName1 = ''; $objUpload->setThumbnailName($thumbnailName1); // create thumbnail $objUpload->createThumbnail(); // change thumbnail size //$objUpload->setThumbnailSize(169, 198); if ($varMediumWidth == '' && $varMediumHeight == '') { $objUpload->setThumbnailSize(); } else { $objUpload->setThumbnailSize($varMediumWidth, $varMediumHeight); } //Add fields in pictures table return $varFileName; } else { $objCore->setErrorMsg(ERROR_ON_UPLOAD); return false; } } } }
function checkProductsValidation($argArrPost) { $objValid = new Validate_fields(); $objCore = new Core(); $objValid->check_4html = true; $_SESSION['sessProducts'] = array(); $objValid->add_text_field('Category', strip_tags($argArrPost['frmfkCategoryID']), 'text', 'y', 255); $objValid->add_text_field('Product Name', strip_tags($argArrPost['frmProductName']), 'text', 'y', 255); $objValid->add_text_field('Product Code', strip_tags($argArrPost['frmProductCode']), 'text', 'y', 255); $objValid->add_text_field('Product Description', strip_tags($argArrPost['frmProductDescription']), 'text', 'y'); $objValid->add_text_field('Product Specifications', strip_tags($argArrPost['frmProductSpecifications']), 'text', 'y'); $objValid->add_text_field('Product Set of Quantity', strip_tags($argArrPost['frmProductQuantity']), 'number', 'y'); //$objValid->add_text_field('Product Quantity Available', strip_tags($argArrPost['frmProductQuantityAvailable']), 'number', 'y'); $objValid->add_num_field('Product Cost', strip_tags($argArrPost['frmProductCost']), 'text', 'y'); //$objValid->add_num_field('Product Total Cost', strip_tags($argArrPost['frmProductActualCost']), 'text', 'y'); if ($objValid->validation()) { $errorMsgFirst = 'Please enter required fields!'; } else { $errorMsg = $objValid->create_msg(); } if (trim($argArrPost['frmProductCost']) != '') { if (!preg_match('/^[0-9]*\\.?[0-9]+$/', strip_tags(trim($argArrPost['frmProductCost'])))) { $errorMsg .= ERR_PRODUCT_PRICE_ERR; } } if (trim($argArrPost['frmProductActualCost']) != '') { if (!preg_match('/^[0-9]*\\.?[0-9]+$/', strip_tags(trim($argArrPost['frmProductActualCost'])))) { $errorMsg .= ERR_PRODUCT_RRP_ERR; } } if ($argArrPost['frmProductSeoFriendlyURL'] != '') { if (preg_match('/[^a-z-A-Z]/', $argArrPost['frmProductSeoFriendlyURL'])) { $errorMsg .= ERR_PRODUCTS_SEO_URL; } } if ($errorMsg) { $_SESSION['sessProducts'] = $argArrPost; $objCore->setErrorMsg($errorMsg); return true; } else { $arrProductCols = array('pkProductID'); if ($argArrPost['frmProductID'] != '') { $varWhereProduct = 'ProductCode =\'' . $argArrPost['frmProductCode'] . '\' AND pkProductID !=\'' . $argArrPost['frmProductID'] . '\''; } else { $varWhereProduct = 'ProductCode =\'' . $argArrPost['frmProductCode'] . '\''; } $arrProductCodeList = $this->select(TABLE_PRODUCTS, $arrProductCols, $varWhereProduct); if ($arrProductCodeList != '') { $objCore->setErrorMsg(ERR_PRODUCT_CODE_EXISTS); $_SESSION['sessProducts'] = $argArrPost; return true; } //check the number of featured count if ($argArrPost['frmProductID'] != '') { $varWhereCondition = 'AND ProductIsFeatured = \'' . $argArrPost['frmProductIsFeatured'] . '\' AND pkProductID != \'' . $argArrPost['frmProductID'] . '\''; } else { $varWhereCondition = 'AND ProductIsFeatured = \'' . $argArrPost['frmProductIsFeatured'] . '\''; } $varColumn = 'pkProductID'; $varResultCount = $this->getNumRows(TABLE_PRODUCTS, $varColumn, $varWhereCondition); $argArrPost['frmProductIsFeatured']; if ($varResultCount >= MAX_FEATURED_COUNT && $argArrPost['frmProductIsFeatured'] == 'Yes') { $objCore->setErrorMsg(ERR_FEATURED_PRODUCT); $_SESSION['sessProducts'] = $argArrPost; return true; } //check for valid image type $objUpload = new upload(); if ($_FILES['frmProductImage']['name'] != '') { $varIsImage = $objUpload->IsImageValid($_FILES['frmProductImage']['type']); if (!$varIsImage) { $varErrorMsg = IMAGE_TYPE_ERROR; $objCore->setErrorMsg(IMAGE_TYPE_ERROR); $_SESSION['sessProducts'] = $argArrPost; return true; } //chekc for image size $varMaxFileSize = MAX_UPLOAD_SIZE; $varFileSize = $_FILES['frmProductImage']['size']; if ($varFileSize > $varMaxFileSize) { $varErrorMsg = FILE_SIZE_ERROR; $objCore->setErrorMsg($varErrorMsg); $_SESSION['sessProducts'] = $argArrPost; return true; } //end chekc for image size } return false; } }