Dan,
I know you can figure this out.
I wanted to have a little fun with an interesting experiment ;)
The sample:
http://getgamesforfree.com/pulpcore/get_data/
The code:
Using the 'Hello World' example as a starter, I altered the update
method in the title scene as follows:
I comment out: //addEvent(new SceneChangeEvent(new HelloWorld(),
300));
and replaced it with:
CoreImage img = null;
try {
img = UrlTest.GetUrlImage("
http://www.interactivepulp.com/images/
logo.png") ;
} catch (Exception e) {
e.printStackTrace();
}
Sprite test = new ImageSprite(img,320,300);
test.setAnchor(.5,.5);
add(test);
img is set by a static method in UrlTest.
Then, in the UrlTest class, I added your code:
public class UrlTest {
public static CoreImage GetUrlImage(String urlStr) {
ByteArray in = null;
Download d = Download.startDownload("
http://myWebSite.com/
get_data.php?url="+urlStr);
while (d.getState() == Download.DOWNLOADING) {
// wait until we're done downloading
}
in = new ByteArray(d.getData());
in.reset();
return CoreSystem.getThisAppContext().loadImage(in);
}
}
That's pretty much your code, but passing the desired urlStr to
get_data.php in a folder accessible to the applet.
Then, put this in the get_data.php
<?php
/* gets the data from a URL */
function get_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
echo get_data($_GET["url"]);
?>
That's fairly standard. I googled it--tweaked it.
It just echos the data. There isn't technically a download. So,
there's never a file on your server.
A php like this is a very interesting little critter open to a lot of
potential for abuse.
It will relay pretty much anything.
I'd add some security to only accept from your applet.