NaN
NaN

Reputation: 9104

How to create a WebService that receives Files in PHP sent from Delphi?

I have a WebService that works that way:

  1. I send a file through ftp into a specific folder in my remote server;
  2. I call a web service in that same server so that the file name and path can be recorded in the data base. Only this way the system will know of the file existence.

I do it that way because I do not know how to make a web service that can receive a file by HTTP POST directly.

The server works under PHP & MySQL.

The client that sends the file and register it is made in Delphi. I use Indy now.

In the future I intend to make it full web but my client is still addicted to windows.

So, can I make a rest web service that receives a pdf file and also receive data about this file, like "from", "to", "description"...? How?

Upvotes: 0

Views: 1473

Answers (1)

jachguate
jachguate

Reputation: 17203

In order to upload a file, you must perform a POST call to your WebService. (You can also perform a PUT operation, but that's not covered in this answer).

The php part:

In php, you use the $_FILES associative array, which contains the items uploaded to the script using the mentioned POST method.

Once you accept the file, you use the move_uploaded_file function to save the file in your server disk, and then you can read the file from there and post it to a database or any other operation you want to perform.

I recommend you to read the referenced articles in the handling file uploads php manual entry.

You can also find a working example on the php file upload w3schools article.

The Delphi part

There are various libraries that allow you to perform HTTP operations from Delphi. My preferred one is Indy Sockets, and you'll find a great number of questions (and answers) here on StackOverflow, for example: Http Post with indy which includes a flie attachment.

Upvotes: 1

Related Questions