vale...
GatorV voy a probar....
Gracias
GatorV
en resumen asi quedo y funciona
Código PHP:
<?php
/**
* Enviar POST
*
* Esta funcion intentara enviar un paquete POST hacia
* la URL especificada, incluso archivos.
*
* <b>NOTE</b> que en caso de fallar algo, se
* devolvera <b>FALSE</b>.
*
* @link http://www.php.net/manual/en/function.fsockopen.php#39868
* @param string $url URL destino
* @param string $args Variables
* @param string $files Archivos
* @return mixed
*/
function upload($url, $args = array(), $files = array())
{
if ( ! preg_match('/^[a-z]{2,6}:\/\/\S+$/', $url)) return FALSE;
elseif ( ! is_callable('fsockopen')) return FALSE;
// reparamos...
$test = parse_url($url);
$path = ! empty($test['path'])? $test['path']: '/';
$path .= ! empty($test['query'])? '?' . $test['query']: '';
$resource = fsockopen($test['host'], ! empty($test['port'])? $test['port']: 80);
if ( ! $resource) return FALSE;
$boundary = '---------------------------'. substr(md5(uniqid('')), 0, 13);
$output = "--$boundary";
// query
if ( ! empty($args))
{
foreach ((array) $args as $name => $value)
{
$output .= "\r\nContent-Disposition: form-data; name=\""
. $name . '"';
$output .= "\r\n\r\n$value\r\n--$boundary";
}
}
// upload
if ( ! empty($files))
{
foreach ((array) $files as $name => $set)
{//--
$data =file_get_contents($set[0]);
//$data = read($set[0]);//aqui me da error
$name = is_numeric($name)? $set[0]: $name;
$output .= "\r\nContent-Disposition: form-data; name=\""
. $name . '"; filename="' . $set[0] . '"';
$output .= "\r\nContent-Type: " . $set[1];
$output .= "\r\n\r\n$data\r\n--$boundary";
}
}
$output .= "--\r\n\r\n";
//HTTP =>
fputs($resource, "POST $path HTTP/1.0\r\n");
fputs($resource, "Content-Type: multipart/form-data; boundary=$boundary\r\n");
fputs($resource, 'Content-Length: ' . strlen($output) . "\r\n");
fputs($resource, "Connection: close\r\n\r\n");
fputs($resource, "{$output}\r\n");//--
$output = '';
while( ! feof($resource)) $output .= fgets($resource, 4096);
return $output;
}
//////////////////////////////////////////////////////////////////////
var_dump(upload(
'http://localhost:256/pruebas_php/pruebas_fsocket/upload.php',
array(
'input_text' => 'Foo',
'input_check' => 'on'
),
array(
'input_file' => array('prueba.txt', 'text/plain'),
//'input_file2' => array('candy.gif', 'image/gif'),
'this_file' => array(__FILE__, 'application/octet-stream')
)
));
?>