file upload with post

Karl Hiramoto karl at hiramoto.org
Sun Mar 15 18:41:14 EDT 2009


Joe Orton wrote:
> On Thu, Mar 12, 2009 at 04:18:26PM +0100, Karl Hiramoto wrote:
>   
>> Is there anyone out there that has some example code of how to do a file  
>> upload with post.   I've used neon before to do some http GET, but not  
>> post.
>>     
>
> If you wish to simply use a file as the POST request body, given an open 
> fd for the file, try:
>
>   ne_request *req = ne_request_create(sess, "POST", path);
>
>   ne_set_request_body_fd(req, fd, 0, <length-of-file>);
>
>   ret = ne_request_dispatch(req);
>   // check for errors from ret
>
>   ne_request_destroy(req);
>
> Regards, Joe
I'm not sure if this is what i want, maybe i didn't ask the question 
correctly.    I need something that will upload to a multipart/form-data 
content type. 

One thing that was not clear to me from the man page of 
ne_set_request_body_fd() is if i would be able to set the 
multipart/form-data  boundry=abcd, and how to separate the different parts.


What i want  is something to do a simple upload to a form like:

<html>
  <form name="upload" action="upload1.php" method="POST" 
ENCTYPE="multipart/form-data">
  Select the file to upload: <input type="file" name="userfile">
  <input type="submit" name="upload" value="upload">
   </form>
<html>

with the PHP to handle it:

<?php
 $uploaddir = 'uploads/'; // Relative path under webroot
 $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
 if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
 echo "File is valid, and was successfully uploaded.\n";
 } else {
 echo "File uploading failed.\n";
 }
?>


--
Thanks






More information about the neon mailing list