Jump to content

Access file on Web Server Help - Noob Question


You are about to reply to a thread that has been inactive for 3609 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi all,

 

As I am finally winding down (I Hope) my current scripting project, I have already started to think about the next one :-) . Part of this one though is going to delve into an area that I have no real experience in and was hoping that someone could point me to some basic tutorials on how-to, or if there are scripts already written in the public domain that I could use as a start that would be just as good (if not better). What I am looking to do is be able to get a file off a web-server (I have one of those) and read it like I would a notecard in the same prim. Now I do realize that it would not be as simple as that, as I cannot imagine I can download a file into a prim, but that is the end result I am looking for.

 

So .. any suggestions?

 

Thanks in advance!

Wanda Soulstar

Link to comment
Share on other sites

You cannot download a file to SL from a webserver - however, you can open a textfile with php, read it line by line and then send the text to SL.

I don't know where you need help doing this - but here are the general steps with the most important commands:

  1. Send a request from SL to your webserver using llHTTPRequest
  2. on the webserver, read the file with fopen
  3. read the file line by line and make a string with the text - if the text is too long (max. number of bytes is 16384). You read a file you opened with fopen with the fgets command
  4. send the string you have built back to SL using the echo command
  5. in your LSL script, use the Http response event to get the text. It's in the body of the response
  • Like 1
Link to comment
Share on other sites

Thanks for the quick reply Darkie .. seems to be much simpler than I thought. Let me repeat what you have said with examples to be certain I have it correct:

 

1) Create the following PHP script and upload it to my webserver directory

<?php$handle = @fopen("/info/infofile.txt", "r");if ($handle) {    while (($buffer = fgets($handle)) !== false) {        echo $buffer;    }       if (!feof($handle)) {        echo "Error: unexpected fgets() fail\n";    }    else    {        echo "eof\n";    }        fclose($handle);}?>

 

2) Create the following script in LSL (only have a section here assuming there is more around this that gets us to the state

key http_request_id;string INFO_URL = "http:\\my_domain.com\info_retriever.php";string END_FILE = "eof" state read_webfile{    state_entry()    {        http_request_id = llHTTPRequest(INFO_URL, [], "");    }     http_response(key request_id, integer status, list metadata, string body)    {        if (request_id = http_request_id)        {             if (body != END_FILE)             {                  //do something with textline from body             }             else             {                  state running;             }        }    }}

 

3) Have an file called infofile text in the indicated location on my server that has lines of data

 

that is it?

Link to comment
Share on other sites

he he .. yes that would bite me wouldn't it :-)

 

Thanks so much Darkie, I have always been a bit weary about pushing out from SL thinking it was going to be more difficult, but you have opened my eyes to a whole new world, I finally can make use of that web server for more than just my personal mail.

On the PHP front, I assume there is some way for the script to get the data passed in the body parameter of the llHTTPRequest call. The wiki shows examples of reading the header that comes, but I was wondering how to get the body parameter?

 

Link to comment
Share on other sites

if Io understand you correctly, you want to pass data from SL to the webserver - right?

First you have to decide, what kind of request you are sending - you spicify that in the HTTP_METHOD part of llHTTPRequest.

If you make a POST request, you insert name-value pairs into the request body - something like:

http_request_id = llHTTPRequest("url", [HTTP_METHOD,"POST",HTTP_MIMETYPE,"text/html; charset=iso-8859-1"], "name=myName&age=20");

 

On the php side, you can use the $_POST array to read the data&colon;

name = $_POST['name'];age = $_POST['age'];

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3609 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...