Aeternus Posted August 30, 2005 Posted August 30, 2005 ?? The boundaries wouldnt be placed within one files content but the point is you could send multiple files and multiple post fields in one HTTP Request and so the boundary is placed between each of these to seperate them. Try setting up a form with multiple fields and multiple files and check it out on ethereal.
albertlee Posted August 30, 2005 Author Posted August 30, 2005 <input type="file" name="UserFile"> <input type="hidden" name="Original"> <input type="submit" value="Send File"> ok. for the fields above, do you know what values are supposed to be given for type "hidden" and type "submit"? thx
Klaynos Posted August 30, 2005 Posted August 30, 2005 Just a small note but the hidden input doesn't have any value :|
albertlee Posted August 30, 2005 Author Posted August 30, 2005 one more question on content length... we know that content length indicate the size of entity-body... so, what does the entity-body include?? boundary, file content, and what?
Aeternus Posted August 30, 2005 Posted August 30, 2005 Ok, heres an example of multiple fields being sent - POST /aeternus/test.php HTTP/1.1 Host: aeternus.no-ip.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6 Accept: text/xml' date='application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Content-Type: multipart/form-data; boundary=---------------------------41184676334 Content-Length: 978 -----------------------------41184676334 Content-Disposition: form-data; name="fileOne"; filename="test.txt" Content-Type: text/plain #!/bin/sh tabRep=' ' vim -n -c ':so $VIMRUNTIME/syntax/2html.vim' -c ":w $2" -c ':qa' $1 > /dev/null 2> /dev/null php space2nbsp.php $2 >> $2 -----------------------------41184676334 Content-Disposition: form-data; name="cheese" cheese -----------------------------41184676334 Content-Disposition: form-data; name="toast" cheese2 -----------------------------41184676334 Content-Disposition: form-data; name="fileTwo"; filename="highlight.sh" Content-Type: application/octet-stream #!/bin/sh tabRep=' ' vim -n -c ':so $VIMRUNTIME/syntax/2html.vim' -c ":w $2" -c ':qa' $1 > /dev/null 2> /dev/null php space2nbsp.php $2 >> $2 -----------------------------41184676334-- [/quote'] Everything after the Content-Length: 978 is the body of the request, or the data being sent. The form associated with this is - <form action="http://aeternus.no-ip.org/aeternus/test.php" enctype="multipart/form-data" method="POST"> <input name="fileOne" type="file" /> <input name="cheese" value="cheese" /> <input name="toast" value="cheese2" /> <input name="fileTwo" type="file"> <input type="submit" /> </form> You'll note that the boundaries seperate each of these fields in the body. This is the way data is represented when the Content-Type is multipart/form-data. Normally if you weren't using this Content Type/ Enctype' date=' the data is sent as Content-Type - application/x-www-form-urlencoded which lays out the Post fields differently as it isnt expecting things such as large files and multiple different data types (usually just talking text fields etc). This is shown below - POST /aeternus/test.php HTTP/1.1 Host: aeternus.no-ip.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Content-Type: application/x-www-form-urlencoded Content-Length: 27 cheese=cheese&toast=cheese2 <form action="http://aeternus.no-ip.org/aeternus/test.php" method="POST"> <input name="cheese" value="cheese" /> <input name="toast" value="cheese2" /> <input type="submit" /> </form> That was just to clarify what was happening. You ask about what can be contained in the body' date=' well pretty much anything you want really, but the specifications for each Content-Type will probably expect the body to provide data in different forms and with different headers etc within the body itself. From what I can see, with the multipart/form-data Content-Type, it expects at least a Content-Disposition header for each field/file (between the boundaries) explaining what the data is and how it is referred to (ie what you called it (name="???" in the html), so you can reference it in CGI's etc like $_POST['cheese''] or $_FILES['fileOne'] in php). It seems you can or must also provide a per file Content-Length declaration telling how long the file data is for any file fields sent. There is probably alot more to it, you might be able to find some links here - http://en.wikipedia.org/wiki/MIME as multipart/form-data is sent as a MIME format. Lastly, when checking ethereal you may not see all of this within one packet as the data is split across multiple TCP/IP packets and so you will have to go through the HTTP packets and pick them out. I did this in these examples and simply spliced the data back together so it can be seen all as one example.
albertlee Posted August 30, 2005 Author Posted August 30, 2005 yeah, I made it...after modifying my code, I can upload my file now.....solely using my java program,...thx very much... Aeternus!!!
albertlee Posted August 30, 2005 Author Posted August 30, 2005 btw, one last question, I never set the content-length in my program, but according to the rfc, content-length is a must-set property...... why my program still works any way?? however, setting content-length is not an easy job though... whateva,..
Aeternus Posted August 30, 2005 Posted August 30, 2005 The URLConnection class seems to work it out and set it anyway, I noticed that when watching what packets the java program sent. It sets most of the headers, just you can alter them or add additional headers as you see fit.
albertlee Posted August 30, 2005 Author Posted August 30, 2005 Alright, the 34th post will now be the last one here.... thx Aeternus for all the helps and others of course... Au Revoir
sal00m Posted September 13, 2005 Posted September 13, 2005 Hello. I'm trying to do the same.... send a file from an applet to a php page..... Please, can you tell me how do you send the file correctly????? I'm trying several days.... and nothing. PS: I apologize for my poor english.
sal00m Posted September 14, 2005 Posted September 14, 2005 Finally i write the code and i send the file correctly, but there is another problem. If the file is bigger than the max_upload_filesize in php.ini, i obtain an error..... is there a solution to upload a file bigger than max_upload_filesize?, upload ffile in parts or something like this. Thx in advance.
Aeternus Posted September 14, 2005 Posted September 14, 2005 php_value upload_max_filesize 10000000 Put that in a .htaccess file in the same directory where 10000000 is the size in bytes that youd like the maximum filesize to be. You can also apparently use K for Kb, M for Mb etc as mentioned here. You might think you could use ini_set() to set that value but as the file has already been uploaded this isnt possible as it has already been handled and setting in the php script would be setting it after the fact. Edit - Forgot to mention this is Apache specific. There are other ways to do it with IIS etc probably.
Klaynos Posted September 14, 2005 Posted September 14, 2005 php_value upload_max_filesize 10000000 Put that in a .htaccess file in the same directory where 10000000 is the size in bytes that youd like the maximum filesize to be. You can also apparently use K for Kb' date=' M for Mb etc as mentioned here. You might think you could use ini_set() to set that value but as the file has already been uploaded this isnt possible as it has already been handled and setting in the php script would be setting it after the fact. This is why I don't let people use .htaccess files other than myself
albertlee Posted September 14, 2005 Author Posted September 14, 2005 This is why I don't let people use .htaccess files other than myself What???? you can actually use the .htaccess files???? how come?? isn't that situated under a certain directory where every one cannot edit it except the site admin???? btw, what is php.ini?? can any just give a short primer of related configuration files on a web server???? thx
Aeternus Posted September 14, 2005 Posted September 14, 2005 Nope, .htaccess files are used by Apache to allow users to do per directory or minor changes without overwriting the main configuration files as Admin. You are limited in what you can actually set and these are only things that the user should be able to set for their personal sites. More information here. It's not as bad as it sounds as, as you can see in one of the PHP links below there is an Option in the main global configuration file that allows you to turn on and off the ability to override already set options and there are also further options to limit or expand the usability of .htaccess files. php.ini is a global configuration file for the php interpreter. It is editable by the server admin and is stored in different places on different installations (mine is stored in the apache config directory /etc/apache2/conf/, i think this is for the php module (mod_php) for apache and there is another one in /etc/php/ for php in general (ie CLI etc)). More information here and here . As for a webserver configuration primer, I'm no expert, Klaynos might be able to help a little more, and perhaps someone with IIS experience or other webservers might be able to help with those (perhaps Pangloss) but here is a link for the beginnings of the Apache config information and googleing Apache and what you wish to know will generally turn up what you wish to know.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now