By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,515 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,515 IT Pros & Developers. It's quick & easy.

PHP, cURL, and File Uploads

P: n/a
HC
Hi everybody :)

I am trying to write a script that makes cURL submit the following form:

<form method="post" action="script.php" enctype="multipart/form-data">
<input type="file" name="somefile">
<input type="submit" value="Send File">
</form>

I've found a few examples of how to do this, but they all require me
creating a file first. I have the data I would like to submit in a PHP
variable, and for security reasons, I would prefer not to write this to
a file.

If anyone has any ideas on this, that would rock all kinds of worlds.

HC :)
Jun 12 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a

HC wrote:
Hi everybody :)

I am trying to write a script that makes cURL submit the following form:

<form method="post" action="script.php" enctype="multipart/form-data">
<input type="file" name="somefile">
<input type="submit" value="Send File">
</form>

I've found a few examples of how to do this, but they all require me
creating a file first. I have the data I would like to submit in a PHP
variable, and for security reasons, I would prefer not to write this to
a file.

If anyone has any ideas on this, that would rock all kinds of worlds.

HC :)


<?php

$post_data = array();

$post_data['foo'] = "bar";
$post_data['beer'] = "good";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://my.domain.com/my_url.php" );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);

if (curl_errno($ch)) {
print curl_error($ch);
}
curl_close($ch);
print "$postResult";
?>

Jun 12 '06 #2

P: n/a
HC
Hi Sjoerd,

Your example runs, but 'foo' and 'beer' seem to be standard form inputs
- they don't appear to simulate a file upload. The script I am
submitting to looks for data from $_FILES - unfortunately, I have no
control over this.

If you have any other ideas, that would be spectacular.

HC

Sjoerd wrote:
<?php

$post_data = array();

$post_data['foo'] = "bar";
$post_data['beer'] = "good";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://my.domain.com/my_url.php" );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);

if (curl_errno($ch)) {
print curl_error($ch);
}
curl_close($ch);
print "$postResult";
?>

Jun 12 '06 #3

P: n/a
In article <OGijg.9242$iF6.2180@pd7tw2no>, e0*@removethis.toao.net
says...
Hi everybody :)

I am trying to write a script that makes cURL submit the following form:

<form method="post" action="script.php" enctype="multipart/form-data">
<input type="file" name="somefile">
<input type="submit" value="Send File">
</form>

I've found a few examples of how to do this, but they all require me
creating a file first. I have the data I would like to submit in a PHP
variable, and for security reasons, I would prefer not to write this to
a file.

If anyone has any ideas on this, that would rock all kinds of worlds.

HC :)


HC

I don't know if this helps but you may want to look at my thread
"about posting forms" I updated 12/12/06 - that may point you in
a useful direction.

I do something that sounds similar to your needs if I understand you
correctly. It won't help if you must use "cURL" though (I dont know what
that does I' afraid)

tony
Jun 13 '06 #4

P: n/a
HC
Thanks Tony! I will check it out. No, I'm not married to cURL - as
long as the solution works; I'm happy :)

-HC
to**@tony.com wrote:
I don't know if this helps but you may want to look at my thread
"about posting forms" I updated 12/12/06 - that may point you in
a useful direction.

Jun 13 '06 #5

P: n/a
Hello,

on 06/12/2006 03:49 PM HC said the following:
Hi everybody :)

I am trying to write a script that makes cURL submit the following form:

<form method="post" action="script.php" enctype="multipart/form-data">
<input type="file" name="somefile">
<input type="submit" value="Send File">
</form>

I've found a few examples of how to do this, but they all require me
creating a file first. I have the data I would like to submit in a PHP
variable, and for security reasons, I would prefer not to write this to
a file.

If anyone has any ideas on this, that would rock all kinds of worlds.


You may want to try this HTTP client class. It supports submitting forms
including uploading files. Take a look at the test_http_post.php example:

http://www.phpclasses.org/httpclient
--

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
Jun 17 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.