How to code "multipart/form-data” in a PHP script ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ed kool
    New Member
    • Aug 2006
    • 1

    How to code "multipart/form-data” in a PHP script ?

    Question how to code "multipart/form-data” in a PHP script ?

    We are trying to make our program trchat.exe work via the following PHP script:


    Code:
     <?php 
     
    $lang = " English to Dutch";
     
    $postdata="select=".$lang."&TEXTAREA1=testtext";
     
    $ch = curl_init(); 
     
    curl_setopt($ch, CURLOPT_URL, 'http://ling98.com/cgi-bin/trchat.exe'); 
     
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
     
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
     
    curl_setopt($ch, CURLOPT_HEADER, 0); 
     
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     
    curl_setopt ($ch, CURLOPT_POST, 1); 
     
     
     
    $content = curl_exec ($ch); 
     
     
     
    curl_close ($ch); 
     
     
     
    print $content; 
     
     
     
    ?>

    Underneath we have the operational javascript,

    Removing all options in the form submit line, exept enctype="multip art/form-data" has no effect on the proper operation of trchat.exe.


    Code:
     <SCRIPT LANGUAGE=JavaScript> 
     
     
     
    var vertaal = "English to Dutch"
     
    var tekst = "textual test"
     
     
     
    mstr = '<form name="myform" action="http://ling98.com/cgi-bin/trchat.exe" method="post" enctype="multipart/form-data" runat="server" type="submit" >'
     
    mstr +='<Input type="text" name="TEXTAREA1" value="'
     
    mstr += tekst
     
    mstr += '" >'
     
    mstr +='<Input type="text" name="select" value="'
     
    mstr += vertaal
     
    mstr += '" >'
     
    mstr += '<input name="" type="submit">'
     
    mstr +='</form>'
     
    document.write (mstr);
     
    document.myform.submit();
     
    </SCRIPT>

    Through PHP we are not able to send the , "multipart/form-data” which seems to be required for trchat.

    Question how to code "multipart/form-data” in a PHP script ?
    Last edited by Niheel; Aug 1 '06, 03:22 PM.
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    Seeming how i have no idea what trchat is or does i don't see where the problem is...

    i don't understand why you are even having the javascript write the form since it is a static document.write the variables are static so why even use javascript.

    Comment

    • bevort
      New Member
      • Jul 2006
      • 53

      #3
      Because you are dutch i advise you to go to http://www.handleidinghtml.nl/ and read about the "multipart/form-data" enctype.

      example:
      <FORM METHOD="post" ACTION="bestemm ing" ENCTYPE="multip art/form-data">
      <INPUT TYPE="file" NAME="upload">
      </FORM>

      As you can see this formwants to upload a file. You are trying to send normal $_POST vars with your javascript.

      Your program wants a file and does not get that.

      Vincent

      Comment

      Working...