As I know the post or simple post will post a file which is already on the server.
Here is how my scripts on server works.Those two are not the same, the former issues a GET request with parameter named xml containing a string file.xml, the second one issues a POST request with the content of path/to/my-file.txt as raw request body.
I can call it this way with file
http://mysite.com/send.php?xml=file.xml
Or I simply call curl with syntax from above
curl -X POST --data-binary @path/to/my-file.txt http://mysite.com/send.php
Here is my php which I callSo you indeed only receive the filename from the request instead of the file content. Thus, the file that the code will read must already exist in the server. It's the server side that's incorrectly coded if you want to be able to send file from anywhere else other than the server.
*****************************
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include_once('xml.php');
$filename = utyGetString($_GET, 'xml', 'php://input');
$xmlData = file_get_contents($filename);
Thanks for the feedback.No, you did not, try on real server separated from your developing computer. Read the documentation of file_get_contents, the first parameter is filename, which can also be a URL, but not something from a post request body. Your code explicitly states that it reads from $_GET, not $_POST, so you're reading only the filename, and because you're running the server on the same computer, it gives a false assumption that you successfully send the file from local.
But with curl I can post a local file.
curl -X POST --data-binary @path/to/my-file.txt http://mysite.com/send.php
I was looking for something similar as curl.
Regards Michoux
No, you did not, try on real server separated from your developing computer. Read the documentation of file_get_contents, the first parameter is filename, which can also be a URL, but not something from a post request body. Your code explicitly states that it reads from $_GET, not $_POST, so you're reading only the filename, and because you're running the server on the same computer, it gives a false assumption that you successfully send the file from local.Actually... I see a function utyGetString() which uses php://input.
php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php://input instead of $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives. Moreover, for those cases where $HTTP_RAW_POST_DATA is not populated by default, it is a potentially less memory intensive alternative to activating always_populate_raw_post_data. php://input is not available with enctype="multipart/form-data".
As I know the post or simple post will post a file which is already on the server.You could use something like FileFormPost.
I am posting a local file from my PC
Just need to correct TFileStream.Create; to TFileStream.Create('');You mean TStringStream.Create('') ??
Response := TStringStream.Create; did not work for me, got an error ...Ah, ok. Maybe you have an older Lazarus/FPC installation. I'm not sure at what point the AString became optional (because for me it is, in the trunk-version).