RTC Forums
November 24, 2024, 07:21:22 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Basic PHP usage  (Read 8193 times)
classic12
Guest
« on: November 10, 2011, 07:29:21 PM »

I have delphi PHP and would like to know how to do the same in PHP as I am doing in delphi with the client app.

ie post a number (Which triggers a MYSql statement on the server)
Then populate some Edit boxes with some field data and an Image showing an image from the Blob field.

This would allow most of the work to be done on the server, and allow us to build Web & IOS apps in tandem.
The beauty of this method is developing the program logic in windows is 100 times quicker than PHP.

Any help appreciated.

Cheers


SteveW
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: November 10, 2011, 07:33:13 PM »

I can't help you with PHP nor Delphi4PHP, but I am sure that PHP has classes which you can use to send HTTP Requests to the Server and receive a Response. On the RTC Server side, use the TRtcDataProvider component to accept such requests from PHP and prepare a response. Or, as an alternative, look for XML-RPC classes in PHP and enable the XML-RPC format on the TRtcServerModule component in your Server, so you can accept and respond to XML-RPC remote calls by using RTC remote functions.

Best Regards,
Danijel Tkalcec
Logged
classic12
Guest
« Reply #2 on: November 10, 2011, 07:55:31 PM »

I need a push in the right direction.

I have added a RtcDataProvider1 and connected to RtcHttpServer1

I then guessed at :
procedure TForm11.RtcDataProvider1DataIn(Sender: TRtcConnection);
begin
                Edit4.Text := ' DATA IN ';
end;

I the tried :

http://mydomain.com:8080/mytest?name=2

So I need.
1. The correct setup for the RtcDataProvider.
2. How to pass a parmeter to the server.
3. I presume I would then be using Get etc in PHP.


Cheers


SteveW
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 on: November 10, 2011, 08:02:25 PM »

You are asking questions which suggest that you have not taken the time to go through the Quick Start lessons, so ... please check the Quick Start examples first, so you can learn the basic concepts of the RTC SDK. Simply going through the first few Quick Start Server Lessons would already have answered your question.

As for the PHP-side ... "Google is your friend". From the PHP-side, a RTC Server is no different than any other Web Server, so the same code you would use in PHP to send a HTTP request to an ASP, JSP or Java Application running on a Web Server also applies to a RTC Server.

Best Regards,
Danijel Tkalcec
Logged
Kevin Powick
RTC Expired
*
Posts: 87


« Reply #4 on: November 11, 2011, 06:40:03 PM »

I then guessed at :
procedure TForm11.RtcDataProvider1DataIn(Sender: TRtcConnection);
begin
                Edit4.Text := ' DATA IN ';
end;

Guessing won't get you too far. Smiley

As Danijel has suggested, there is a lot of good information available on how to do this.  PHP has classes for both XML-RPC and straight XML processing, so you can choose how you wish to handle it on the PHP side.  The PHP side will have no special considerations with regard to RTC.  On the RTC side you would use rtcFunction components for XML-RPC.

Mac programming for OSX/iOS also has support for XML-RPC, so maybe that is the route you should consider.  However you could also adopt a REST style approach using GET/POST to handle passing parameters and data.   The format of the data is up to you, but typically it would be XML or JSON.  In this case, you would look at the DataProvider components of RTC.

--
Kevin Powick
Logged

Linux is only free if your time is worthless
classic12
Guest
« Reply #5 on: November 15, 2011, 12:20:34 PM »

Ok guys

I own up I got caught by the teacher and got sent to the headmaster  Roll Eyes

I have added a dataprovider and can use the show the time.
In my delphi php app I use:

    function Button1Click($sender, $params)
    {
          $message = 'http://80.5.54.130:8080/time';

$reply = file_get_contents($message);
$this->Edit1->Text = $reply;

    }

This displays the time in the edit box as expected.
I now need to display an image.

I use :

procedure TForm11.RtcDataProvider1DataReceived(Sender: TRtcConnection);
begin
             with Sender as TRtcDataserver do
              if Request.Complete then
              write ('<html><head><title></title></head> <body>&nbsp; <img src="62.jpg"></body></html>');


end;

and in php:

    function Button1Click($sender, $params)
    {
          $message = 'http://80.5.54.130:8080/time';

$reply = file_get_contents($message);
$this->Image1->ImageSource = $reply;

    }

This results in a greyed out image box when I right click I get
Forbidden

You don't have permission to access /<html><head><title></title></head> <body>  <img src= on this server.

1. Is this the correct approach. Ie the goal is to be able to use the same server to query the database and return text & images for both IOS and php apps.
2. Where do I set the permissions for the server app.

Cheers

SteveW
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #6 on: November 15, 2011, 01:28:35 PM »

This has nothing to do with permissions.

From my understanding of your PHP example, $this->Image1->ImageSouce is expecting an URL which points at the image file on a Web Server, but the response you are sending from the RTC Server is a HTML file. Since PHP is trying to use the contents of that HTML file as an URL to request the image, it fails and reports an error. And in this case, "Forbidden" is probably as good a guess as any.

In other words, you are probably telling PHP now to load the image using this URL:
<html><head><title></title></head> <body>&nbsp; <img src="62.jpg"></body></html>

I'm not familiar with PHP, but since you are probably using PHP to generate a HTML page, my guess is that you should write a DataProvider in your RTC Server which would return the image file *contents* and then assign the URL for your DataProvider to the $this->Image1->ImageSource property in PHP.

If you don't know what an URL is, it is a combination of protocol (http), host address (80.5.54.130), host port (8080) and the requested file URI (/myimage/62.jpg). For example http://80.5.54.130:8080/myimage/64.jpg - for which you would need a DataProvider accepting the URL "/myimage/64.jpg" and use the Write() method to print out the contents of the image "64.jpg". For example ...
Write(Read_File('64.jpg'));
... if the image is located in the file '64.jpg' inside the current folder on the Server.

For more information on sending files from a Web Server, take a look at Server Quick Start lessons about sending out small files and sending out large files.

Best Regards,
Danijel Tkalcec
Logged
classic12
Guest
« Reply #7 on: November 15, 2011, 04:25:18 PM »

Hi,

I have gone through the quickstart lessons.

The localhost/time & localhost/Square work okay.

I have added the image files into the project folder.

When I use localhost/64.jpg or localhost/64.bmp I get a firebug error :

<img src="http://localhost/64.jpg" alt="The image “http://localhost/64.jpg” cannot be displayed, because it contains errors.">

Cheers

SteveW
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #8 on: November 15, 2011, 04:49:54 PM »

Did you go through Quick Start Server lessons for sending out small files and sending out large files as I've suggested in my last reply?

Sending out HTML containing some URL won't get your file to the Browser. You need a rtcDataProvider which will process the request and write the "file" content out when requested by a Client.

PS. You can also take a look at the File_Server Demo, which is located in the Demos/File_Server folder and implements an example File Server by using a single TRtcDataProvider component.

Best Regards,
Danijel Tkalcec
Logged
classic12
Guest
« Reply #9 on: November 15, 2011, 05:13:11 PM »

Cheers

I did go through the lessons but I missed the data folder and place the files in the root.....

so they failed.


Onwards and upwards.....
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #10 on: November 15, 2011, 05:29:58 PM »

I take it your problem is now solved?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.029 seconds with 16 queries.