Warning, /webapps/ocs-server/gfx3/src/ENetworkSocket.class.php.save is written in an unsupported language. File is not indexed.

0001 <?php
0002 
0003 /*
0004  *   TRT GFX 3.0.1 (beta build) BackToSlash
0005  * 
0006  *   support:   happy.snizzo@gmail.com
0007  *   website:   http://trt-gfx.googlecode.com
0008  *   credits:   Claudio Desideri
0009  *   
0010  *   This software is released under the MIT License.
0011  *   http://opensource.org/licenses/mit-license.php
0012  */ 
0013 
0014 class ENetworkSocket{
0015         
0016         private $target_server;
0017         private $postdata;
0018         private $numpost = 0;
0019         private $uploaded_file = 0;
0020         
0021         public function __construct($srv){
0022                 $this->set_target_server($srv);
0023         }
0024         
0025         public function set_target_server($srv){
0026                 $this->target_server = rtrim($srv,"/")."/";
0027         }
0028         
0029         /* Example post data:
0030          * $postdata = (
0031                         array(
0032                                 'var1' => 'some content',
0033                                 'var2' => 'doh'
0034                         )
0035                 );
0036          *
0037          */
0038         public function set_post_data($data){
0039                 $this->postdata = http_build_query($data);
0040                 $this->numpost = count($data);
0041         }
0042         
0043         public function set_upload_file($file){
0044                 $this->uploaded_file = $file;
0045         }
0046         
0047         /*
0048          * performs a get request and return raw xml
0049          */
0050         public function get ($string){
0051                 $url = $this->target_server.$string;
0052                 $result = file_get_contents($url);
0053                 return $result;
0054         }
0055         
0056         /*
0057          * performs a post request and return raw xml
0058          */
0059         public function post ($string){
0060                 if($this->uploaded_file){
0061                         
0062                         
0063                         $ch = curl_init();
0064                         
0065                         // Assign POST data
0066             $this->postdata['localfile'] = new CurlFile($this->uploaded_file, 'application/octet-stream', $this->uploaded_file);
0067                         
0068                         curl_setopt($ch, CURLOPT_URL, $this->target_server.$string ); // imposto l'URL dello script destinatario
0069                         curl_setopt($ch, CURLOPT_POST, true ); // indico il tipo di comunicazione da effettuare (POST)
0070                         curl_setopt($ch, CURLOPT_POSTFIELDS, $this->postdata); // indico i dati da inviare attraverso POST
0071                         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
0072                         $result = curl_exec($ch);
0073                         
0074                         if (curl_errno($ch)) { print curl_error($ch); }
0075                         curl_close($ch); // close CURL session
0076 
0077                         return $result;
0078                         
0079                 } else {
0080                         $opts = array('http' =>
0081                                 array(
0082                                         'method'  => 'POST',
0083                                         'header'  => 'Content-type: application/x-www-form-urlencoded',
0084                                         'content' => $this->postdata
0085                                 )
0086                         );
0087                         
0088                         $context = stream_context_create($opts);
0089                         $url = $this->target_server.$string;
0090                         $result = file_get_contents($url, false, $context);
0091                         return $result;
0092                 }
0093 
0094         }
0095 }
0096 
0097 ?>