cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: help needed uploading file via a form

From: Thomas Townsend <tlt_at_vwg.com>
Date: Tue, 30 Sep 2008 08:36:02 -0400

My postfields:

$postfields= array("__VIEWSTATE" => $viewstate,
                                 "upload_quote" => "Upload");

In several examples I've seen on the internet, the file is not
specified in the post fields and neither is the submit!

As a test, I changed from 'post' to 'get' in the form to see what was
being sent. Only 'viewstate' and 'quote_upload' were. So I assumed the
file spec was being sent elsewhere.

As for the submit not being sent along, the httpfileupload.php example
on haxx by Daniel Stenberg does not send the submit along:
<?php

//
// This sample shows how to fill in and submit data to a form that
looks like:
//
// <form enctype="multipart/form-data"
// action="somewhere.cgi" method="post">
// <input type="file" name="sampfile">
// <input type="text" name="filename">
// <input type="text" name="shoesize">
// <input type="submit" value="upload"> <---- HERE IS THE
SUBMIT IN THE FORM
// </form>
//
// Pay attention to:
// #1 - the input field names (name=)
// #2 - the input field type so that you pass the upload file to the
right
// name
// #3 - what URL to send the POST to. The action= attribute sets it.
//
// Author: Daniel Stenberg

    $uploadfile="/tmp/mydog.jpg";
    $ch = curl_init("http://formsite.com/somewhere.cgi");
    curl_setopt($ch, CURLOPT_POSTFIELDS,
                array('sampfile'=>"@$uploadfile",
                      'shoesize'=>'9',
                      'filename'=>"fake name for file")); <---- NO
SUBMIT HERE???
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $postResult = curl_exec($ch);
    curl_close($ch);
    print "$postResult";
}

?>

However, I have tried using all, both , neither and any other
combination, all to no positive effect!

TomT

On Sep 29, 2008, at 5:33 PM, Stephen Pynenburg wrote:

> What do you have for $postfields?
> The file should given as such:
> $file = "upload.txt";
> $postfields = array('file_path'=>"@$file", 'viewstate'=>'etc',
> 'submit'=>'etc...');
>

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-09-30