ehh Posted December 27, 2007 Share Posted December 27, 2007 I'm trying to create a PHP 4 script which should send form data to another webpage. The form contains a field where you can choose a file to be uploaded. By using curl from the command line I get what I want: $ curl -F "foo=1" -F "bar=1" -F [email protected] http://localhost/printpost.php # (printpost.php prints $_POST and $_FILES.) Array ( [foo] => 1 [bar] => 1 ) Array ( [file] => Array ( [name] => foo.jpg [type] => image/jpeg [tmp_name] => /tmp/phpMsEeas [error] => 0 [size] => 1317 ) ) At http://www.enyem.com/wiki/index.php/Send_POST_request_(PHP) I found a function that let me send POST requests from PHP 4 without having to use libcurl (which the web server don't have). I can send the foo and bar fields to printpost.php without problems: <?php echo do_post_request("http://localhost/bilogmc/printpost.php", "foo=1&bar=2"); ?> gives Array ( [foo] => 1 [bar] => 2 ) Array ( ) My question is: how can I send along a file as if it were being uploaded (what happens with curl -F upload=@localfilename )? Quote Link to comment https://forums.phpfreaks.com/topic/83359-upload-file-from-php-with-post/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.