function set_post_vars($array, $parent_key = null) { $temp = array(); foreach ($array as $key => $value) { $key = isset($parent_key) ? sprintf('%s[%s]', $parent_key, urlencode($key)) : urlencode($key); if (is_array($value)) { $temp = array_merge($temp, set_post_vars($value, $key)); } else { $temp[$key] = urlencode($value); } } return $temp; }
$_post_body .= "--{$_data_boundary}\r\n"; $_post_body .= "Content-Disposition: form-data; name=\"{$key}\"; filename=\"{$file_info['name']}\"\r\n"; $_post_body .= 'Content-Type: ' . (empty($file_info['type']) ? 'application/octet-stream' : $file_info['type']) . "\r\n\r\n"; if (is_readable($file_info['tmp_name'])) { $handle = fopen($file_info['tmp_name'], 'rb'); $_post_body .= fread($handle, filesize($file_info['tmp_name'])); fclose($handle); } $_post_body .= "\r\n"; } $_post_body .= "--{$_data_boundary}--\r\n"; $_request_headers .= "Content-Type: multipart/form-data; boundary={$_data_boundary}\r\n"; $_request_headers .= "Content-Length: " . strlen($_post_body) . "\r\n\r\n"; $_request_headers .= $_post_body; } else { $array = set_post_vars($_POST); foreach ($array as $key => $value) { $_post_body .= !empty($_post_body) ? '&' : ''; $_post_body .= $key . '=' . $value; } $_request_headers .= "Content-Type: application/x-www-form-urlencoded\r\n"; $_request_headers .= "Content-Length: " . strlen($_post_body) . "\r\n\r\n"; $_request_headers .= $_post_body; $_request_headers .= "\r\n"; } $_post_body = ''; } else { $_request_headers .= "\r\n"; } fwrite($_socket, $_request_headers); //