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

Posted on 2008-11-17
Last Modified: 2013-12-13
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

Question by:fedra

    Author Comment

    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 :)

    Accepted Solution


    Author Comment

    I will reopen the question but in a different way.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Suggested Solutions

    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
    The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now