📄 adminImages.php

Size: 2,338 bytes
Path: /home/islandholiday/public_html/admin/panel/adminImages.php
Modified: 2020-11-01 19:10:32
<?php
include_once "assets/includes/autoloader.includes.php";

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



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

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

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




// Read files from 
if($request == 2){
    $file_list = array();
    
   
         
        $Driverget= $ima->getSingleUser($userID);
        $driver_row= $Driverget->fetch(PDO::FETCH_ASSOC);
        $p=DecryptInput($driver_row['profileImage']);

        $pictures = array();

        array_push($pictures, $p);
        // Read files
       
        
    

    // 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,16);
    $roomD= $ima->deleteAdminimage($pic);
    //$_SESSION['result']= $pic;
    exit;
    //unlink($filename); exit;
}