Hello,
I have problem in client and server file exchange. I have server installed in my computer. I have php file which is used to connect and query the database. Another person which is client will send me an xml file and I have to write piece of server software to read the xml file and save the xml element to php varable. Finally I have to send an new xml file to back to the client.
My question is can php(in server side) used to read and send xml file from server side? if not, which programming language could do it. the xml file was send by post method or curl command from client.Can you provide me some useful link or example code which deal with interaction between client and server.I am really new in this field.
Thank you very much
client and server file exchange
Moderator: General Moderators
Re: client and server file exchange
PHP is perfectly suitable for this task, as it is designed as a server-side language for the web. Do you have web server installed. If so, then depending how the file is sent, you need either to read it from $_FILES (if it is attachment in a multipart/form-data request), $_POST (standart POST request), or php://input (read RAW post data, if the content is not assigned to a variable name, e.g. there is no xml=... in the body)
To output XML back to the client you need simple echo statement.
If you don't have a web server, you have either to install one, or to write your script to listen on a socket (see fsockopen for more details)
To output XML back to the client you need simple echo statement.
If you don't have a web server, you have either to install one, or to write your script to listen on a socket (see fsockopen for more details)
Re: client and server file exchange
Hello,
Thank you very much. I do have server installed in my computer. My first task is to get the xml file from client.
The person who act as client will submits data to server by using POST. she also mentioned that he will use the command
curl -v -d @parameters.xml http://localhost:....
I have to read the data and creates a new xml file. Server returns location of new file and client follows location with a request(get). I am little bit confuse about curl command. Does curl command have to work together with post?
if the client will send me the xml file this way, which method could be the best solution?
Thanks again.
Thank you very much. I do have server installed in my computer. My first task is to get the xml file from client.
The person who act as client will submits data to server by using POST. she also mentioned that he will use the command
curl -v -d @parameters.xml http://localhost:....
I have to read the data and creates a new xml file. Server returns location of new file and client follows location with a request(get). I am little bit confuse about curl command. Does curl command have to work together with post?
if the client will send me the xml file this way, which method could be the best solution?
Thanks again.
Re: client and server file exchange
hello,
The xml file will be send to me(server) by http post method.
If I want to read the xml file and save its element to php variable , should I use $http_post_vars[]
http://in.php.net/manual/en/reserved.variables.post.php
I found the link about http post request
http://ruturajv.wordpress.com/2005/12/2 ... t-request/
But it didn´t really give me an idea how to do it.
Thanks
The xml file will be send to me(server) by http post method.
If I want to read the xml file and save its element to php variable , should I use $http_post_vars[]
http://in.php.net/manual/en/reserved.variables.post.php
I found the link about http post request
http://ruturajv.wordpress.com/2005/12/2 ... t-request/
But it didn´t really give me an idea how to do it.
Thanks
Re: client and server file exchange
http_post_vars is deprecated since long time
$_POST is the correct way.
But since the client will issue @filename command, I bet the file will be available in the $_FILES
You can read here how to handle them:
http://www.php.net/manual/en/features.file-upload.php
Then you can use SimpleXML for parsing the XML file
you can save it to a file and use header() to send the Location header
But since the client will issue @filename command, I bet the file will be available in the $_FILES
You can read here how to handle them:
http://www.php.net/manual/en/features.file-upload.php
Then you can use SimpleXML for parsing the XML file
you can save it to a file and use header() to send the Location header
Re: client and server file exchange
hello,
thanks. I think the link that your give me is really useful. In the post method upload method web page, it saids :
"Files will, by default be stored in the server's default temporary directory, unless another location has been given with the upload_tmp_dir directive in php.ini. The server's default directory can be changed by setting the environment variable TMPDIR in the environment in which PHP runs. Setting it using putenv() from within a PHP script will not work. This environment variable can also be used to make sure that other operations are working on uploaded files, as well. "
Is that mean if the client post me an xml file with post or get method, it will appear in my wwwroot folder automatically. I just need to write some method to upload the file from wwwroot folder. If have iis server installed in my computer, I don´t need to write anything about socket?
I think I don´t really use $_post function to download the files from client, right? instead, using $_files()
<?php
$uploaddir = './';
$uploadfile = $uploaddir . basename($_FILES['parameters']['name']);
foreach ($_FILES["parameter"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name = $_FILES["pictures"]["name"][$key];
move_uploaded_file($tmp_name, "data/$name");
}
}
?>
thnaks
clare
thanks. I think the link that your give me is really useful. In the post method upload method web page, it saids :
"Files will, by default be stored in the server's default temporary directory, unless another location has been given with the upload_tmp_dir directive in php.ini. The server's default directory can be changed by setting the environment variable TMPDIR in the environment in which PHP runs. Setting it using putenv() from within a PHP script will not work. This environment variable can also be used to make sure that other operations are working on uploaded files, as well. "
Is that mean if the client post me an xml file with post or get method, it will appear in my wwwroot folder automatically. I just need to write some method to upload the file from wwwroot folder. If have iis server installed in my computer, I don´t need to write anything about socket?
I think I don´t really use $_post function to download the files from client, right? instead, using $_files()
<?php
$uploaddir = './';
$uploadfile = $uploaddir . basename($_FILES['parameters']['name']);
foreach ($_FILES["parameter"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name = $_FILES["pictures"]["name"][$key];
move_uploaded_file($tmp_name, "data/$name");
}
}
?>
thnaks
clare