Guest User

MaJyx Scanner PHP API

a guest
Aug 7th, 2014
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1. <?php
  2.    
  3. /*
  4.     +++++++++++SAMPLE+++++++++++
  5.     $target_path = "uploads/";
  6.    
  7.     $target_path = $target_path . basename( $_FILES['file']['name']);
  8.        
  9.     if(!move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
  10.         die("There was an error uploading the file, please try again!");
  11.     }
  12.    
  13.     $file_path = $target_path;
  14.    
  15.     $scan = scanFile($file_path);
  16.     $result = json_decode($scan);
  17.     foreach($result as $av){
  18.         echo($av->name . '  -  ' . $av->result);
  19.         echo('<br />');
  20.     }
  21. */
  22.  
  23.     function scanFile($file_path) {
  24.         $id='YourID';
  25.         $token='YourToken';
  26.        
  27.         global $UPLOAD_DIRECTORY;
  28.        
  29.         $ch = curl_init();
  30.         curl_setopt($ch, CURLOPT_HEADER, 0);
  31.         curl_setopt($ch, CURLOPT_VERBOSE, 1);
  32.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  33.         curl_setopt($ch, CURLOPT_URL, "http://v2.scan.majyx.net/scan.php");
  34.         curl_setopt($ch, CURLOPT_POST, true);
  35.         $post = array(
  36.                 'token'=>$token,
  37.                 'id'=>$id,
  38.                 'file'=>'@'.$file_path,
  39.         );
  40.  
  41.         curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  42.        
  43.         $result = curl_exec($ch);
  44.         $err     = curl_errno($ch);
  45.         $errmsg  = curl_error($ch);
  46.        
  47.         if(!empty($err)){
  48.             $result = $errmsg;
  49.         }
  50.        
  51.         curl_close($ch);
  52.        
  53.         return $result;
  54.     }
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment