If I am posting to a form like this:

<FORM ENCTYPE="multipart/form-data" METHOD=POST  ACTION="http://www.somesite.com/cgi-bin/blahh/index.pl?post" NAME="message" TARGET="_self">

What is the proper way to URL encode my PHP/CURL POST data to be POSTed to this form?

Thanks very much.

    I don't get it... URL encode? You dont send anything in the URL when POST'ing the form... the only time the URL is altered is when you use the GET method.

      This is taken directly from the CURL manual at:

      http://curl.haxx.se/docs/manual.html

      POST (HTTP)
      
        It's easy to post data using curl. This is done using the -d <data>
        option.  [B]The post data must be urlencoded[/B].
      
        Post a simple "name" and "phone" guestbook.
      
          curl -d "name=Rafael%20Sagula&phone=3320780" \ 
                  http://www.where.com/guest.cgi
      
        How to post a form with curl, lesson #1:
      
        Dig out all the <input> tags in the form that you want to fill in. (There's
        a perl program called formfind.pl on the curl site that helps with this).
      
        If there's a "normal" post, you use -d to post. -d takes a full "post
        string", which is in the format
      
          <variable1>=<data1>&<variable2>=<data2>&...
      
        The 'variable' names are the names set with "name=" in the <input> tags, and
        the data is the contents you want to fill in for the inputs. The data *must*
        be properly URL encoded. That means you replace space with + and that you
        write weird letters with %XX where XX is the hexadecimal representation of
        the letter's ASCII code.
      
      

        Can anybody show me a simple example of an explicity multipart/form-data POST?

        Thanks.

          You mean like an HTTP protocol log? It'd look something like this:

          POST /submit/form.php HTTP/1.1
          Host: mysite.com
          Connection: close
          (bunch of client headers.. browser, etc. etc.)
          
          field1=some+data+here&field2=hey+there%2C&field3=this+is+some+POST+data
          
          
            bradgrafelman wrote:

            You mean like an HTTP protocol log?

            An multipart/form-data POST example could be:

            1. CURL example of a m/f-d POST
            2. fopen() example
            3. others??

            I'm not being lazy, i'm starting over, because my prior attempts at POSTing to a multipart/form-data website doesn't work.

            Basically i want to see any example of PHP code which can successfully POST to a multipart/form-data via any known method...

              Unless you echo out an HTML form there probably is no example of using a multipart/form-data
              mostly because POST data comes from a FORM which is HTML.
              So if you insist here is a form with multipart/form-data that uploads files and the action send it to a page where you do whatever you want with those files.

              <html>
              <head>
              <title>Send an Email</title>
              </head>
              <body>
              <center><h3>Send an Email with inline images</h3>
              </center>
              <form action="fivepartinline.php" method="POST" enctype="multipart/form-data">
              <p>To: <input type="text" name="to" size='45' />
              From: <input type="text" name="from" size='45' />
              Subject: <input type="text" name="subject"  /></p>
              <p>Message:<br />
              <textarea cols="70" rows="15" name="message"></textarea></p>
              <p>File Attachment 1: <input type="file" name="fileatt" /></p>
              <p>File Attachment 2: <input type="file" name="fileatt2" /></p>
              <p>File Attachment 3: <input type="file" name="fileatt3" /></p>
              <p>File Attachment 4: <input type="file" name="fileatt4" /></p>
              <p>File Attachment 5: <input type="file" name="fileatt5" /></p>
              <p><input type="submit" value="Send" /></p>
              </form>
              </body>
              </html>

                Please write the PHP code/CURL code that would dump the data to your example form.

                  Using cURL...

                  $ch = curl_init('http://www.somesite.com/cgi-bin/blahh/index.pl?post');
                  
                  curl_setopt($ch, CURLOPT_HEADER, FALSE);
                  curl_setopt($ch, CURLOPT_POST, TRUE);
                  
                  curl_setopt($ch, CURLOPT_POSTFIELDS, 'field1=hey+there&field2=data+here%2C&field3=etc');
                  
                  curl_exec($ch);
                  curl_close($ch);
                    bradgrafelman wrote:

                    curl_setopt($ch, CURLOPT_POSTFIELDS, 'field1=hey+there&field2=data+here%2C&field3=etc');

                    Do you encode ALL special characters?

                    Do you use the urlencode()/rawurlencode function?

                      Write a Reply...