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 file=@foo.jpg 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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.