Advertisement
Guest User

Untitled

a guest
Jul 5th, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.85 KB | None | 0 0
  1. <?php
  2. // ROUTES[2] IS = IMAGE_ID + UNIQID
  3. // EXAMPLE: 23
  4. $file_name = (int)$routes[2];
  5. $file = '/home/husliste/images/'.$file_name;
  6.  
  7. $sql = "SELECT i.image_filetype as filetype, i.image_type as type, i.image_key "
  8.         . "FROM images i "
  9.         . "WHERE i.image_deleted IS NULL "
  10.         . "AND i.image_id = :filename LIMIT 1";
  11. $results = $db_connect->prepare($sql);
  12. $results->bindParam(':filename', $file_name, PDO::PARAM_INT);
  13. $results->execute();
  14. $db_image = $results->fetchAll(PDO::FETCH_ASSOC);
  15. foreach($db_image as $output){
  16.     if($output['type']){
  17.         // CREATE HEADER
  18.         switch($output['filetype']){
  19.             case "gif": $ctype="image/gif"; break;
  20.             case "png": $ctype="image/png"; break;
  21.             case "jpeg":
  22.             case "jpg": $ctype="image/jpeg";break;
  23.             default:
  24.         }
  25.         header('Content-type: '.$ctype);
  26.         // CREATE FILE PATH
  27.         $file_path = $file.'.'.$output['filetype'];
  28.        
  29.         // =========================================== //
  30.         // PLAN
  31.         if($output['type'] === '1'){
  32.             if(checkPlanAccess($output['image_key'])){
  33.                 if(file_exists($file_path)){
  34.                     echo file_get_contents($file_path);
  35.                 }else{$error_code = 4;}
  36.             }else{$error_code = 4;}
  37.         }
  38.         // PROFILE PICTURE
  39.         elseif($output['type'] === '2' && $check_session){
  40.             if(file_exists($file_path)){
  41.                 $image = file_get_contents($file_path);
  42.                 echo $image;
  43.             }else{$error_code = 4;}
  44.         }
  45.         // COMPANY LOGO
  46.         elseif($output['type'] === '3' && $check_session){
  47.             if(file_exists($file_path)){
  48.                 echo file_get_contents($file_path);
  49.             }else{$error_code = 4;}
  50.         }
  51.         // CUSTOMER LOGO
  52.         elseif($output['type'] === '4'){
  53.             if(checkCustomerAccess($output['image_key'])){
  54.                 if(file_exists($file_path)){
  55.                     echo file_get_contents($file_path);
  56.                 }else{$error_code = 4;}
  57.             }else{$error_code = 4;}
  58.         }
  59.         // CUSTOMER PROJECT IMAGES
  60.         elseif($output['type'] === '5'){
  61.             if(checkCustomerProjectAccess($output['image_key'])){
  62.                 if(file_exists($file_path)){
  63.                     echo file_get_contents($file_path);
  64.                 }else{$error_code = 4;}
  65.             }else{$error_code = 4;}
  66.         }
  67.         // SUPPLIER LOGO
  68.         elseif($output['type'] === '6'){
  69.             if(checkSupplierAccess($output['image_key'])){
  70.                 if(file_exists($file_path)){
  71.                     echo file_get_contents($file_path);
  72.                 }else{$error_code = 4;}
  73.             }else{$error_code = 4;}
  74.         }else{
  75.             $error_code = 4;
  76.         }
  77.     }else{
  78.         $error_code = 4;
  79.     }
  80. }
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement