Posting to my own html form

Discussion in 'PHP' started by ntesla123, Mar 9, 2011.

  1. #1
    This is my attempt to make an upload script to upload images to my own website.
    <?php
    $ch = curl_init("http://*******.com/imgupload.html");  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,
                array('file'=>"@/home/user/mypic.jpg",
    		      'submit'=>'Submit'));
    $postResult = curl_exec($ch);
    curl_close($ch);
    print "$postResult";
    ?>
    Code (markup):
    The working upload form I'm trying to post to:
    
    <html>
    <body>
    
    <form action="upload_file.php" method="post"
    enctype="multipart/form-data">
    <label for="file">Filename:</label>
    <input type="file" name="file" id="file" />
    <br />
    <input type="submit" name="submit" value="Submit" />
    </form>
    
    </body>
    </html> 
    Code (markup):
    Why doesn't this work?
     
    ntesla123, Mar 9, 2011 IP
  2. SedNaX

    SedNaX Active Member

    Messages:
    1,326
    Likes Received:
    59
    Best Answers:
    0
    Trophy Points:
    90
    #2
    Why do you use curl? You can use $_FILES, way easier.
     
    SedNaX, Mar 9, 2011 IP
  3. ntesla123

    ntesla123 Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Sorry, I don't know how to do it using $_FILES, is there a tutorial about that?

    I haven't found anything about how to use it as a client.
     
    ntesla123, Mar 9, 2011 IP