Delphi and PHP. I want to send a POST from Delphi to a PHP script

I want my Delphi 7 app to send a very small package of data (under 200 bytes) to a PHP script.
The script will store the data to the local disk in a file.

I use ICS 6 component to send the POST request.

I have PHP the script which is working when it receive the POST from a HTML form, but it is not working when it receives that POST from my app.

So, what is wrong with the POST sent by my app?

Delphi code (from ICS examples folder):

procedure THttpPostForm.PostButtonClick(Sender: TObject);
VAR Data : String;
    Data :=       'MAX_FILE_SIZE=30000&';
    Data := Data+ 'nume_fis=' + {UrlEncode}(Trim(sFileName))+ '&';
    Data := Data+ 'Submit=Submit';

    HttpCli.SendStream := TMemoryStream.Create;
    HttpCli.SendStream.Write(Data[1], Length(Data));
    HttpCli.SendStream.Seek(0, 0);
    HttpCli.RcvdStream := TMemoryStream.Create;
    HttpCli.URL := Trim(ActionURLEdit.Text);

PHP code:



    $str = '';
    foreach($_POST as $P=>$p){
        $str .= "$P => $p\r\n";
    $str .= "====================\r\n";
    $f = fopen('post.txt', 'a+');
    fwrite($f, $str);
    print('POST request saved to disk as post.txt<br>');      
else { print('No POST received!'); }

print('Debugging 2:<br>');
print('Size: '.$_FILES['nume_fis']['size'].'<br>');
print('Name: '.$_FILES['nume_fis']['name'].'<br>');
print('Eror: '.$_FILES['nume_fis']['error'].'<br>');
print('Type: '.$_FILES['nume_fis']['type'].'<br>');
print('Tmp_name: '.$_FILES['nume_fis']['tmp_name'].'<br>');

$uploaddir = '';
$uploadfile = $uploaddir . basename($_FILES['nume_fis']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['nume_fis']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n"; }

echo 'Here is some more debugging info:';

print "</pre>";

HTML form to upload data:
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="index.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->    
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: 
    <input name="nume_fis" type="file" size="40" />
    <input type="submit" value="Send File" />

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fedraAuthor Commented:
Of course you don't have to write the PHP code that stores the info to disk (this will be another post in PHP section) but only the Delphi code :)
fedraAuthor Commented:
Points increased.

Link to ICS component: 

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fedraAuthor Commented:
I will reopen the question but in a different way.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.