📄 tourImages.php

Size: 2,366 bytes
Path: /home/islandholiday/public_html/admin/panel/old-php-files/tourImages.php
Modified: 2020-11-01 19:11:44
<?php
include_once "assets/includes/autoloader.includes.php";

// Upload directory
$target_dir = "uploads/images/";
$target_dir2 = "uploads/images/";
$ima = New Images();
$request = 1;
if(isset($_POST['request'])){
    $request = $_POST['request'];
}



// Upload file
if($request == 1){
    

    $temp = explode(".", $_FILES['file']['name']);
    $fileName ='zanzibar excursion-'.'-'.rand(0, 100000000).'-'. round(microtime(true)) . '.' . end($temp); 
    $target_file = $target_dir . $fileName;

    $msg = "";
    if (move_uploaded_file($_FILES["file"]["tmp_name"],$target_file)) {
        $Tid=$_POST['Tid'];
        $images_add= $ima->addtourImages($Tid,$fileName);  
        //$msg = "Successfully uploaded";
    }else{
        $msg = "Error while uploading";
    }
    echo $msg;
    exit;
}

// Read files from 
if($request == 2){
    $file_list = array();
    $Tid=$_POST['Tid'];
    
   
         
        $tourget= $ima->gettourimages($Tid);
        $pictures = array();
        // Read files
        while($tour_row = $tourget->fetch(PDO::FETCH_ASSOC)){
                
                $p=DecryptInput($tour_row['pic1']);
                array_push($pictures, $p);

                
        }
        
    

    // Target directory
    $dir = $target_dir;
   
    if (is_dir($dir)){
     
        if ($dh = opendir($dir)){





            while (($file = readdir($dh)) !== false){

                if($file != '' && $file != '.' && $file != '..' && in_array($file, $pictures)){

                    // File path
                    $file_path = $target_dir.$file;
     
                    // Check its not folder
                    if(!is_dir($file_path)){
                        
                        
                        $size = filesize($file_path);

                        $file_list[] = array('name'=>$file,'size'=>$size,'path'=>$file_path);
          
                    }
                }
     
            }
            closedir($dh);
        }
    }

    echo json_encode($file_list);
    exit;
}


// Remove file
if($request == 3){
    $filename = $target_dir.$_POST['name']; 

    $pic= substr($filename,15);
    $roomD= $ima->deleteTourimage($pic);
    //$_SESSION['result']= $pic;
    exit;
    //unlink($filename); exit;
}