Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. Sending FILE post data through PHP code

Sending FILE post data through PHP code

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
questionphpcomtutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yulianto
    wrote on last edited by
    #1

    Is there a way to send FILE post data through PHP code. I found a code which send common POST data: fputs($fp, "POST $path HTTP/1.1\r\n"); fputs($fp, "Host: $host\r\n"); fputs($fp, "Referer: $referer\r\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-length: ". strlen($data) ."\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $data); How do I send $_FILES data through POST. Is that posible?


    Don't work hard, but work effectively. Travel guide | invest money

    C G 2 Replies Last reply
    0
    • Y Yulianto

      Is there a way to send FILE post data through PHP code. I found a code which send common POST data: fputs($fp, "POST $path HTTP/1.1\r\n"); fputs($fp, "Host: $host\r\n"); fputs($fp, "Referer: $referer\r\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-length: ". strlen($data) ."\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $data); How do I send $_FILES data through POST. Is that posible?


      Don't work hard, but work effectively. Travel guide | invest money

      C Offline
      C Offline
      cjoki
      wrote on last edited by
      #2

      they are referenced in a different variable...$_FILES. But you need to have an input element of the type files in your post form first. So someething like

      Name:
      Img:

      You would access the form elements with... $_POST['action'] for the submit button $_POST['user'] for the user field $_FILES['pict'] for the pict field. Keep in mind this is an array and has a number addition values. You can read more about that here http://www.php.net/manual/en/features.file-upload.php[^]

      1 Reply Last reply
      0
      • Y Yulianto

        Is there a way to send FILE post data through PHP code. I found a code which send common POST data: fputs($fp, "POST $path HTTP/1.1\r\n"); fputs($fp, "Host: $host\r\n"); fputs($fp, "Referer: $referer\r\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-length: ". strlen($data) ."\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $data); How do I send $_FILES data through POST. Is that posible?


        Don't work hard, but work effectively. Travel guide | invest money

        G Offline
        G Offline
        Graham Breach
        wrote on last edited by
        #3

        Yes, it is possible. To save you having to encode the request yourself, I would recommend using something like http://pear.php.net/package/HTTP_Request2[^] - it has an addUpload method for uploading files.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups