Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2010
    Posts
    31

    Uploading to my own form

    This is my attempt to make an upload script to upload images to my own website.
    Code:
    <?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";
    ?>
    The working upload form I'm trying to post to:
    Code:
    <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>
    Why doesn't this work?

  2. Try this:
    PHP Code:
    <?php
    $ch 
    curl_init("http://*******.com/imgupload.html");  
    curl_setopt($chCURL_HTTPHEADER"Content-type: multipart/form-data");
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
    curl_setopt($chCURLOPT_POSTFIELDS,
                array(
    'file'=>"@/home/user/mypic.jpg",
                  
    'submit'=>'Submit'));
    $postResult curl_exec($ch);
    curl_close($ch);
    var_dump($postResult);
    ?>
    I added the content-type. In a form that also necessary in order to upload files.

    During development it's better to var_dump() variables as it might be a boolean value which print doesn't show. Of course if development is done, you can just go print it.

  3. #3
    Join Date
    Jan 2010
    Location
    Sweden
    Posts
    130
    The script should go against upload_file.php, not imgupload.html
    Please do the needful..

Similar Threads

  1. [PHP] uploading a file from a web form
    By Omega-Mark in forum Programming Discussion
    Replies: 2
    Last Post: 04-06-2005, 12:06 PM
  2. Request: text form and image uploading script (PHP)
    By I'd Hit It in forum Other Offers & Requests
    Replies: 0
    Last Post: 03-18-2005, 07:48 PM
  3. Replies: 0
    Last Post: 09-09-2003, 01:41 PM
  4. Replies: 2
    Last Post: 08-30-2003, 05:06 PM
  5. Uploading files via a form
    By Joshua44 in forum Programming Discussion
    Replies: 6
    Last Post: 10-17-2002, 10:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •