cotonti.com : Sending a PHP generated image as multipart/form data https://www.cotonti.com Last topic posts Cotonti en Tue, 02 Dec 2025 12:43:48 -0000 GHengeveld
"curl http://".escapeshellarg($oXml->ip)."/upload?token=
".escapeshellarg(urlencode($oXml->token))." -F 
file=@".escapeshellarg($filename)." -F 
title=".escapeshellarg($title)."
-Fsubmit=Verstuur"
The final script will likely (depending on success of the project) be hosted on the same servers (a cluster of about 1500 servers actually), so cURL is definately supported.
My current testing script looks like this:
<?php
$ch = curl_init("http://somesite.com/upload.php"); // Link to upload script
curl_setopt($ch, CURLOPT_POST, true); // Set method to POST
curl_setopt($ch, CURLOPT_POSTFIELDS, array('uploaded'=>"@005.jpg")); // Form fields are passed in the array, form data is prefixed with @
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_exec($ch);
curl_close($ch);
?>

For more information read the Hyves API MediaUpload documentation (english).]]>
Sun, 15 Mar 2009 06:13:40 -0000
Trustmaster PEAR::HTTP_Client and PEAR::HTTP_Request - it has built-in support for POSTing files.]]> Sun, 15 Mar 2009 01:53:45 -0000 Orkan @Koradhil: yes, thats the rough example. Just before going online, Im always making a "target" script to test everything, from headers, user-agent to final data integrity - if they are equal to the results returned by a browser. Just use print_r($_SERVER), print_r($_FILES) etc...]]> Sat, 14 Mar 2009 12:36:19 -0000 Kilandor You should go on a PHP forum, this is not the place.
Not true thats exactly what this area of the froums is for.

@kordahil

To use that script above, as oc said you have to have curl library installed on your host. Actually you would likely only get bannned due to spamming of such attempts.

But to use that script you will have to look at the site, and find the inputs and fill in the form input names and stuff. And have it set to fill in the appropriate data into those fields.

Why can you not jsut upload the file yourself, i'm assuming its a large image? I mean you could do a localhost and send it that way and still generate the image how you need too.]]>
Sat, 14 Mar 2009 07:32:04 -0000
oc
But, cURL is a library so not usable on every server. And even you accomplish what you try, probably server will ban you after short time.]]>
Sat, 14 Mar 2009 06:56:00 -0000
GHengeveld
I've searched a bit and found the following example:
<?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">
//   </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"));
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   $postResult = curl_exec($ch);
   curl_close($ch);
   print "$postResult";
}

?>

Could this be what I'm looking for?]]>
Sat, 14 Mar 2009 05:58:53 -0000
Orkan cURL is your friend ;-)]]> Sat, 14 Mar 2009 01:51:05 -0000 GHengeveld
Perhaps it is possible by not building a jpeg in the generator script, but just send the raw data. I doubt it will work, it's just something I came up with.]]>
Fri, 13 Mar 2009 04:26:59 -0000
Kilandor Fri, 13 Mar 2009 04:17:58 -0000 GHengeveld Normally this script will only accept images that are submitted using <input type="file" />, but I want to use the PHP generated image, without having to save the file to disk and manually select it for upload.

Is there any way to trick the upload script to think it is receiving image data instead of the image url? I have no control over the upload script, I can only call it with an html form, by providing an upload token and form data in the POST.

(To me more precise, I want to upload something to Hyves.nl using it's API.)]]>
Fri, 13 Mar 2009 04:07:05 -0000