Ver Mensaje Individual
  #2 (permalink)  
Antiguo 30/07/2009, 07:51
Avatar de ACX_POISON
ACX_POISON
 
Fecha de Ingreso: abril-2008
Ubicación: Talca-Chile
Mensajes: 750
Antigüedad: 16 años
Puntos: 7
mmm....

que interezante voy a probar de inmediato..

Se Agradece...

sabes tengo un problema estoy probando tal cual

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('')), 013);
    
$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 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($resource4096);
    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'), *solo un archivo
    
'this_file' => array(__FILE__'application/octet-stream')
  )
));  
?>
pero me da un error en la linea 52 ( $data = read($set[0]);//aqui me da error) que read no esta definida como funcion, no sera fread ¿?..

PD: me intereza probar este sistema .
__________________
Me junto con los que Saben, Queriendo Saber.

Última edición por GatorV; 30/07/2009 a las 10:02