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

curl-and-php

File upload via HTTP post to a http page (web form)

From: Somogyi Gergely <gsomogyi_at_freemail.hu>
Date: Tue, 26 Jun 2007 14:25:46 +0200

Dear All,

I would like to send a form from my server to an other server. The form
contains text fields, etc and also file type fields. I have tried to do it
with the below HTML and CURL codes, but unfortunately it does nothing.

This is the form to which I would like to send the file (only file fields
are here, I can send text fields without a problem):
<form name="form1" enctype="multipart/form-data" method="post"
action="a.php">
  <label>Test
  <input type="file" name="file">
  </label>
  <p>
    <label>Upload
    <input type="submit" name="Submit" value="Submit">
    </label>
  </p>
</form>

This is "a.php" (which is actioned above), as you can see, it only copies
the file to temp directory:
<?php
move_uploaded_file($_FILES['file']['tmp_name'], 'temp/uploadedtest.jpg');
?>

I am using this curl code to upload the file, but unfortunately when using
the above script does not copy the file:
<?php
$ch = curl_init();
$image = "/temp/uploadedfile.jpg";
$post['file'] = "@$image";
curl_setopt($ch, CURLOPT_URL,"b.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$testPage = curl_exec ($ch);
curl_close ($ch);
?>
I have written the above code using sample codes from the Internet...

What can be the problem? Do I miss something here?

Thank you,
Gergely

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2007-06-26