FineUploader / fine-uploader

Multiple file upload plugin with image previews, drag and drop, progress bars. S3 and Azure support, image scaling, form support, chunking, resume, pause, and tons of other features.
https://fineuploader.com
MIT License
8.18k stars 1.87k forks source link

how to make this to upload three images path to database #2047

Closed isharamperera closed 6 years ago

isharamperera commented 6 years ago

?php require_once $_SERVER['DOCUMENT_ROOT'].'/ecommerce/core/init.php'; include 'includes/head.php'; include 'includes/navigation.php';

if(isset($_GET['add']) || isset($_GET['edit'])) {
    $brandQuery = $db->query("SELECT * FROM brand ORDER BY brand");
    $parentQuery = $db->query("SELECT * FROM categories WHERE parent = 0 ORDER BY category");

    $title = ((isset($_POST['title']) && $_POST['title'] != '')?sanitize($_POST['title']) : '');
    $brand = ((isset($_POST['brand']) && !empty($_POST['brand']))?sanitize($_POST['brand']) : '');
    $category = ((isset($_POST['child']) && !empty($_POST['child']))?sanitize($_POST['child']) : '');
    $parent = ((isset($_POST['parent']) && !empty($_POST['parent']))?sanitize($_POST['parent']) : '');

    if(isset($_GET['edit'])) {
        $edit_id = (int)$_GET['edit'];
        $productResults = $db->query("SELECT * FROM products WHERE id = '{$edit_id}'");
        $product = mysqli_fetch_assoc($productResults);

        $title = ((isset($_POST['title']) && !empty($_POST['title']))?sanitize($_POST['title']) : $product['title']);
        $brand = ((isset($_POST['brand']) && !empty($_POST['brand']))?sanitize($_POST['brand']) : $product['brand']);
        $category = ((isset($_POST['child']) && $_POST['child'] != '')?sanitize($_POST['child']) : $product['categories']);

        $parentQ = $db->query("SELECT * FROM categories WHERE id = '{$category}'");
        $parentResult = mysqli_fetch_assoc($parentQ);
        $parent = ((isset($_POST['parent']) && !empty($_POST['parent']))?sanitize($_POST['parent']) : $parentResult['parent']);
    }

    if($_POST) {
        //$title = sanitize($_POST['title']);
        //$brand = sanitize($_POST['brand']);
        $categories = sanitize($_POST['child']);
        $price = sanitize($_POST['price']);
        $list_price = sanitize($_POST['list_price']);
        $sizes = sanitize($_POST['sizes']);
        $description = sanitize($_POST['description']);
        $dbpath = '';

        $errors = array();
        if(!empty($_POST['sizes'])) {
            $sizeString = sanitize($_POST['sizes']);
            $sizeString = rtrim($sizeString, ',');
            $sizesArray = explode(',', $sizeString);
            $sArray = array();
            $qArray = array();
            foreach($sizesArray as $ss) {
                $s = explode(':', $ss);
                $sArray = $s[0];
                $qArray = $s[1];
            }
        } else {
            $sizesArray = array();
        }

        $required = array('title', 'brand', 'price', 'parent', 'child', 'sizes');
        foreach($required as $field) {
            if($_POST[$field] == '') {
                $errors[] = 'All fields with an anterisk are required!';
                break;
            }
        }

        if(!empty($_FILES)) {
            var_dump($_FILES);
            $photo = $_FILES['photo'];
            $name = $photo['name'];
            $nameArray = explode('.', $name);
            $fileName = $nameArray[0];
            $fileExt = $nameArray[1];
            $mime = explode('/', $photo['type']);
            $mimeType = $mime[0];
            $mimeExt = $mime[1];
            $tmpLoc = $photo['tmp_name'];
            $fileSize = $photo['size'];

            $allowed = array('png', 'jpg', 'jpeg', 'gif');
            $uploadName = md5(microtime()).'.'.$fileExt;
            $uploadPath = BASEURL.'images/products/'.$uploadName;
            $dbpath = '/ecommerce/images/products/'.$uploadName;
            if($mimeType != 'image') {
                $errors[] .= 'The file must be an image.';
            }
            if(!in_array($fileExt, $allowed)) {
                $errors[] .= 'The file extension must be a png, jpg, jpeg, or gif.';
            }
            if($fileSize > 15000000) {
                $errors[] .= 'The file size must be under 15 megabytes.';
            }
            if($fileExt != $mimeExt && ($mimeExt == 'jpeg' && $fileExt != 'jpg')) {
                $errors[] .= 'File extension does not match the file.';
            }
        }

        if(!empty($errors)) {
            echo display_errors($errors);
        } else {
            /* Upload file and insert into database. */
            move_uploaded_file($tmpLoc, $uploadPath);
            $insertSql = "INSERT INTO products (title, price, list_price, brand, categories, image, description, sizes) VALUES ('{$title}', '{$price}', '{$list_price}', '{$brand}', '{$categories}', '{$dbpath}', '{$description}', '{$sizes}')";
            $db->query($insertSql);
            header("Location: products.php");
        }
    }

?>

Product


<?php } else {

$presults = $db->query("SELECT * FROM products WHERE deleted = 0");
if(isset($_GET['featured'])) {
    $id = (int)$_GET['id'];
    $featured = (int)$_GET['featured'];
    $db->query("UPDATE products SET featured = '{$featured}' WHERE id = '{$id}'");
    header("Location: products.php");
}

?>

Products

Add Product


query("SELECT * FROM categories WHERE id = '{$childID}'"); $child = mysqli_fetch_assoc($result); $parentID = $child['parent']; $presult = $db->query("SELECT * FROM categories WHERE id = '$parentID'"); $parent = mysqli_fetch_assoc($presult); $category = $parent['category'].' ~ '.$child['category']; ?>
Product Price Category Featured Sold
  0

<?php } include 'includes/footer.php';