Forum Moderators: coopster

Message Too Old, No Replies

How to make request when using $_POST

I want to make a post-request and save the data in my db

         

Henrik

5:26 pm on Oct 5, 2003 (gmt 0)

10+ Year Member



Hey!

I want to make a post-request from a programming language (in this case delphi) and save the data to a MySQL database.

The data I want to save is a single file. I don't need to know the name of the file nor the filetype so it's quite simple but how should my request look like and how do I get access to the file in php?

kind regards
Henrik

RonPK

2:36 pm on Oct 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey Henrik, welcome to WebmasterWorld.

Your situation is not entirely clear to me. Could you please give some more infomration?
* user enters info in a web form
* submitting the form means posting the info to a PHP-script
* the script calls a Delphi-app
* or what?

Henrik

3:55 pm on Oct 6, 2003 (gmt 0)

10+ Year Member



Hey! Thanks for the nice welcome :)

Instead of making the user enter information in a web form I want delphi to send the http-post to my server.
Then my php-script should catch the file submittet and save it in my MySQL db.
I know exactly what type, and name the file has so I only need to store the filedata (i guess that might make it a little easier).

My mainproblem is how the post-request should look like and how I access the filedata in php.
The rest I know how to do :)

Thanks again
Henrik

lorax

4:15 pm on Oct 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hello Henrik, welcome to WebmasterWorld!

Assumption - Delphi is used to pass variables to PHP script which puts the data into MySQL.

$_POST [us4.php.net] is the array that contains form post variables so you'd need to pass your PHP script this array for it to appear if a form submitted the info. So if you have a "name" field the corresponding field in the array would need to look like $_POST["name"].

To access the data you need to use a SELECT (see MySQL website) [mysql.com] query (see PHP website) [us4.php.net] the MySQL db for the data. At that point you can do with it as you like.

jatar_k

4:28 pm on Oct 6, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can build the POST request however you like actually.

for our API functions we use key/value pairs where some values are built into tokenized strings. PHP can then cut them up and sort them out how it likes.

Timotheos

4:31 pm on Oct 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a good article on how to mimic a post request [zend.com] using php. Hopefully this will give you some idea of how to implement it in delphi. Otherwise you might study these DevArticles [devarticles.com].

lorax

5:01 pm on Oct 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>> you can build the POST request however you like actually

I wondered about that. In reality, would you really need to use a POST at all?

jatar_k

5:12 pm on Oct 6, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



really it comes down to a method that is recognized on both sides.

php has to know how to get at it so using post makes it fairly straight forward.

Henrik

5:25 pm on Oct 6, 2003 (gmt 0)

10+ Year Member



hmm. So what I should do is something like this :

POST /foo/index.php HTTP/1.1
Host: <A REF="http://www.zend.com:80/">www.zend.com:80</A>
Content-Type: application/x-www-form-urlencoded
Content-Length: 42
var1=filedata......blablablablablablablablablablablablablablablablablabla

Should I format it with URLencoding or something similar?
If not then what happens when the file has the content: "hey&var2=somedata"
wouldn't php take that as a second variable named var2?

I don't know if Delphi can do this encoding but i bet I can find a component that does the job.

jatar_k

5:31 pm on Oct 6, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



encoding would be better if you think that kind of data will be in there.

It's the same thing we always have to do

take the time to understand the data and then program for what you didn't foresee ;)

Henrik

6:00 pm on Oct 6, 2003 (gmt 0)

10+ Year Member



Ok thanks everybody.

I think I'm gonna give it a try.

lorax

6:11 pm on Oct 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>> don't know if Delphi can do this encoding

It's been awhile since I worked with Delphi but I'm pretty sure it'll do what you need. The last version I worked ith (v3) had functions for working with URLs.