Generally, what happens in the sequence of requests is:
- The client asks the server for a page;
- The server receives the request and looks for the PHP source to use;
- The server processes ALL the PHP code to valid HTML code that the browser can use.
- The server sends the finished HTML code to the client;
- You use an AJAX request to get the image url from the server to the client.