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

curl-and-php

Re: help needed uploading file via a form

From: Stephen Pynenburg <spynenburg_at_gmail.com>
Date: Mon, 29 Sep 2008 17:33:36 -0400

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

-Stephen
On Mon, Sep 29, 2008 at 1:25 PM, Thomas Townsend <tlt_at_vwg.com> wrote:

> My system:
> Linux 2.6.18-92.el5
> PHP 5.1.6 (cli) (built: Jun 12 2008 05:02:35)
> libcurl 7.15.5
>
> I am trying to upload a file through a form. The steps I follow are:
>
> 1) visit the login page to get the __VIEWSTATE variable <--ok
> 2) login <--ok
> 3) visit the upload page to get __VIEWSTATE <-- ok
> 4) upload the file <-- NOT OK!!!
>
> Here is the form:
>
> <form name="Form1" method="post" action="quote_upload.aspx" id="Form1"
> enctype="multipart/form-data">
> <input type="hidden" name="__VIEWSTATE" value="fickshurt" />
> <input name="file_path" id="file_path" type="file" style="WIDTH: 392px;
> HEIGHT: 22px" size="46" />
> <input type="submit" name="upload_quote" value="Upload" id="upload_quote"
> />
> </form>
>
> I have read a hundred web pages, tried a hundred different things, and all
> I get back is either 1) 403 Forbidden or 2) 500 Internal Server Error.
>
> Here is the current set of CURLOPTs I'm using (some of which are currently
> commented out.
>
> curl_setopt($ch, CURLOPT_COOKIEFILE, $cookypath);
> //curl_setopt($ch, CURLOPT_COOKIEJAR, $cookypath);
> curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
> //curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
> //curl_setopt($ch, CURLOPT_REFERER, $upload_url);
> //curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
> //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
> curl_setopt($ch, CURLOPT_HEADER, 1);
> curl_setopt($ch, CURLOPT_URL, $upload_url);
> curl_setopt($ch, CURLOPT_VERBOSE, 2);
> //curl_setopt($ch, CURLOPT_POST, 1);
> curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
> //curl_setopt($ch, CURLOPT_UPLOAD, 1);
> //curl_setopt($ch, CURLOPT_INFILE, $fp);
> //curl_setopt($ch, CURLOPT_INFILESIZE, filesize($uploadfile));
> curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
>
> Can somebody outline a solution or prompt me for more information? I've
> spent four days on this already.
>
> Thanks,
> TomT
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>

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