filename) return; if (!@file_exists($this->filename)) return; $mimetype = $this->mime_guess($this->filename); $this->postarray["new[mimetype]"] = $mimetype; $urla = eregi_replace("http[s]*:\/\/", "", $this->URL); $a = strpos( $urla,"/"); $host = substr($urla,0,$a); $location = substr($urla,$a+1); $boundary = "phpmole".md5(time()); $fh = fopen($this->filename,"r"); $data = fread($fh,filesize($this->filename)); fclose($fh); $body ="--$boundary\r\n"; foreach ($this->postarray as $k => $v) { $body .= "Content-Disposition: form-data; name=\"".urldecode($k) . "\"\r\n\r\n". $v . "\r\n". "--$boundary\r\n"; } $body .= "Content-Disposition: form-data; name=\"test\"; filename=\"".basename($this->filename)."\"\r\n" . "Content-Type: $mimetype\r\n" . "Content-Transfer-Encoding: base64\r\n\r\n" . chunk_split(base64_encode($data)) . "\r\n". "--$boundary--\r\n\r\n"; $headers = "POST /$location HTTP/1.1\r\n" . "Authorization: Basic " . base64_encode($this->username.":".$this->password) . "\r\n". "User-Agent: phpmole\r\n". "Host: $host:80\r\n". "Pragma: no-cache\r\n". "Expect: 100-continue\r\n". "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*\r\n". "Content-Length: ". strlen($body)."\r\n". "Content-Type: multipart/form-data; boundary=$boundary\r\n\r\n"; return $headers. $body; } function get() { //debug_echo("curl: $URL, $postarray, $filename"); //echo "curl : $URL\n"; $ch = curl_init(); $poststring = ""; if ($this->postarray && is_array($this->postarray)) foreach ($this->postarray as $k => $v) { if (!is_array($v)) { $poststring .= "&" .urlencode($k)."=". urlencode($v); continue; } // its an array - post values as $k[0] if (count($v)) { for ($i=0;$i< count($v);$i++) { if (!is_array($v[$i])) { $poststring .= "&" .urlencode($k)."%5B".$i."%5D=". urlencode($v[$i]); continue; } if (count($v[$i])) for ($j=0;$jfilename); $poststring = substr($poststring,1); if ($headers = $this->curl_upload_headers()) { curl_setopt($ch,CURLOPT_CUSTOMREQUEST, $headers); //debug_echo ($headers ); } else { curl_setopt ($ch, CURLOPT_POSTFIELDS, $poststring); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); if ($this->username) curl_setopt ($ch, CURLOPT_USERPWD,$this->username.":".$this->password); } curl_setopt ($ch, CURLOPT_URL, $this->URL); curl_setopt ($ch, CURLOPT_SSLVERSION, 3); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt ($ch, CURLOPT_WRITEFUNCTION, array(&$this,"curl_read")); curl_setopt ($ch, CURLOPT_HEADERFUNCTION, array(&$this,"curl_header_read")); $this->debug("EXEC"); $this->result_string = ""; $result = curl_exec ($ch); $r = curl_error($ch); if ($r) $this->result_string = $r; $this->curlinfo = curl_getinfo($ch); curl_close($ch); $this->debug(serialize($this->curlinfo)); return; } function curl_read($ch,$string) { $len = strlen($string); if (class_exists("gtk")) while (gtk::events_pending()) gtk::main_iteration(); $this->result_string .= $string; $this->emit($string); //echo "GOT $string"; return $len; } function curl_header_read($ch,$string) { $len = strlen($string); if (class_exists("gtk")) while (gtk::events_pending()) gtk::main_iteration(); //$this->result_string .= $string; //$this->emit($string); echo "HEADER: GOT $string\n"; return $len;//$len; } var $_counter = 0; // sequence counter var $_id; // id recieved from request function emit(&$string) { if (!$this->return_chunks) return; $this->_counter++; dba_replace("{$this->_id}:{$this->_counter}",$string,$this->dba_handle); } function start() { $homedir = getenv("HOME"); if (substr(PHP_OS, 0, 3) == 'WIN') $homedir = "C:\Program Files"; $this->dba_handle = dba_open($homedir . "/.phpmole-IDE/phpmole_IPC_in.dbm", "w","db2"); $data = dba_fetch($this->_id,$this->dba_handle); if (!$data) { echo "FAIL TO GET {$this->_id}\n"; exit; } $request = unserialize($data); $object_vars = get_object_vars($request); foreach($object_vars as $k=>$v) { echo "SETTING $k to $v\n"; $this->$k = $v; } $this->dba_handle = dba_open($homedir . "/.phpmole-IDE/phpmole_IPC_out.dbm", "c","db2"); $this->get(); if (!$this->return_chunks) dba_replace("{$this->_id}:0",$this->result_string,$this->dba_handle); dba_close($this->dba_handle); /* delete the key !*/ exit; $this->dba_handle = dba_open($homedir . "/.phpmole-IDE/phpmole_IPC_in.dbm", "w","db2"); dba_delete($this->_id,$this->dba_handle); dba_close($this->dba_handle); } /* * static start, open the dba file, * get the request_object (deserialize) */ function static_start($request_id) { $fetch = &new phpmole_webfetch(); $fetch->_id = $request_id; $fetch->start(); } function static_start_url($URL) { $fetch = &new phpmole_webfetch(); $fetch->URL = $URL; $fetch->get(); return $fetch->result_string; } function debug($s) { echo "$s\n"; } } $a = trim($argv[count($argv)-1]); if ($a{0} != "h") { phpmole_webfetch::static_start(); exit; } echo phpmole_webfetch::static_start_url($a); echo "\n"; ?>