Jump to content

Upload file from PHP with POST


ehh

Recommended Posts

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 )?

Link to comment
https://forums.phpfreaks.com/topic/83359-upload-file-from-php-with-post/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.