Link to home
Start Free TrialLog in
Avatar of wpearsall
wpearsall

asked on

Upload A File To A PHP Script... And Also Pass A Posted Value....

OK, heres the deal.

I need to upload a file to a webserver.  This file is going to be a .gif file, not larger then 14.5kb.

Now, along with uploading this file, i will need to POST a value to the PHP script i wish to use called "USER" (IE: User=MrBob),

Now, how can i upload this image to my webserver, using a .php file as the server-side part, along with the username?

I dont mind using other controls for this [however i would prefer not to use the webbrowser control, as i want to be able to limit the file types to just gif etc in my application, and i need to upload this image practically on load of the application, as "Invisible" as possible.

BTW: I know how to handle the file once it is passed to the PHP Script, etc to copy it from my upload temp directory to a proper file etc :)

Thanks Guys.
Wayne
Avatar of tkalchev
tkalchev
Flag of Germany image

Here is a log of a POST action. It is posting to a php script post.php the following :

Variable, called text1 with value 77
A GIF file (eche.gif).



///------------------- Starting here ----------------------------

POST /post.php HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) Opera 7.11  [en]
Host: localhost
Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
Accept-Language: en;q=1.0
Accept-Charset: windows-1252, utf-8, utf-16, iso-8859-1;q=0.6, *;q=0.1
Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0
Connection: Keep-Alive, TE
TE: deflate, gzip, chunked, identity, trailers
Content-length: 712
Content-Type: multipart/form-data; boundary=----------ZcpvRS7HNeFzxVsIlOwdUo


------------ZcpvRS7HNeFzxVsIlOwdUo
Content-Disposition: form-data; name="MAX_FILE_SIZE"

1000
------------ZcpvRS7HNeFzxVsIlOwdUo
Content-Disposition: form-data; name="file1"; filename="eche.gif"
Content-Type: image/gif

GIF89a

------------ZcpvRS7HNeFzxVsIlOwdUo
Content-Disposition: form-data; name="text1"

77
------------ZcpvRS7HNeFzxVsIlOwdUo
Content-Disposition: form-data; name="upload_file"

Upload!
------------ZcpvRS7HNeFzxVsIlOwdUo--
 


///-----------------END----------------


So, you must build a request like this and send it to the port 80 of your web server.
Just noticed, to have the data from your example, replace

Content-Disposition: form-data; name="text1"

77


with

Content-Disposition: form-data; name="User"

MrBob
Note, that

GIF89a

Should be the binary dump of your Gif file.
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial