post thru fsockopen

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi there

Im tring to send a file  with a php script, Im using php 5.2 on a Win
2003 server. At the other end I just save the file and process the data
and print the result, then fetch the output and write a report. But this
doesn't work, any one got an idea? The file never get to the other end?
When I do a var_export($_POST) is empty.


This is the code I use:
function postFile($file,$host,$path)
{
$remote_page = "http://".$host.$path;
$boundary =
"---------------------------".substr(md5(rand(0,32000)),0,10);

// read the file
$fp = @fopen($file,"r");
if (!$fp) die ("Cannot read $file !!");
$content_file = fread($fp,filesize($file));
fclose($fp);

// define HTTP POST DATA
$data = "--$boundary\n".
"Content-Disposition: form-data; name=\"file\"; filename=\"$file\"\n".
"Content-Type: application/octet-stream\n\n$content_file".
"--$boundary--\r\n\r\n";

$msg = "POST $remote_page HTTP/1.0\n".
"Content-Type: multipart/form-data; boundary=$boundary\n".
"Content-Length: ".strlen($data)."\r\n\r\n";

// Open socket connection ...
$f = fsockopen($host,80, $errno, $errstr, 30);
if ($f)
{

// Send the data
fputs($f,$msg.$data);

// retrieve the response
$result="";

while (!feof($f)) {
$result.=fread($f,1024);
}

fclose($f);
// write the response (if needed)
return $result;
} else {
die ("Cannot connect !!!");
}
}

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux