I found this in the PHP manual... go figure... I slap myself for not looking 
there first...

If you want to post $_POST vars and (in this case) one file named userfile to 
$remote_server and $remote_url.

<?php
        // get the necessary data
        $file_name = $_FILES['userfile']['name'];     // the file
        $tmp_name = $_FILES['userfile']['tmp_name'];     // the file
        $content_type = $_FILES['userfile']['type'];     // the file mime type
        
        srand((double)microtime()*1000000);
        $boundary = "---------------------".substr(md5(rand(0,32000)),0,10);
        
        // Build the header
        $header = "POST $remote_url HTTP/1.0\r\n";
        $header .= "Host: $remote_server\r\n";
        $header .= "Content-type: multipart/form-data, boundary=$boundary\r\n";
        // attach post vars
        foreach($_POST AS $index => $value){
            $data .="--$boundary\r\n";
            $data .= "Content-Disposition: form-data; name=\"".$index."\"\r\n";
            $data .= "\r\n".$value."\r\n";
            $data .="--$boundary\r\n";
        }
        // and attach the file
        $data .= "--$boundary\r\n";
        $content_file = join("", file($tmp_name));
        $data .="Content-Disposition: form-data; name=\"userfile\"; 
filename=\"$file_name\"\r\n";
        $data .= "Content-Type: $content_type\r\n\r\n";
        $data .= "".$content_file."\r\n";
        $data .="--$boundary--\r\n";
        $header .= "Content-length: " . strlen($data) . "\r\n\r\n";
                 // Open the connection
        $fp = fsockopen($remote_server, 80);
        // then just 
        fputs($fp, $header.$data);
        fclose($fp);
?>


----- Original Message ----
From: Mathew Nik Foscarini <[EMAIL PROTECTED]>
To: [email protected]
Sent: Saturday, May 10, 2008 1:57:31 PM
Subject: Re: Sending POST to Cake website via PHP


Thanks, I didn't know wget could do HTTP POST operations.


----- Original Message ----
From: Marcin Domanski <[EMAIL PROTECTED]>
To: [email protected]
Sent: Saturday, May 10, 2008 12:56:28 PM
Subject: Re: Sending POST to Cake website via PHP


Look at wget[1] /curl (its supported in all major scripting languages
including php) dpending how much scripting do you need.
wget --post-file --post-data
If the files/data is static or rotated/automated already i would use
wget - just throw it into cron.
If you need any scripting language... you can use anything :) bash
+wget , php, python, perl (if you're into tortures ;)

[1] http://linuxreviews.org/man/wget/



-- 
Marcin Domanski
http://kabturek.info

________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile. Try it now.


      
____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to