Using LC server to check for existence of mp3 on our web server?
selander at tkf.att.ne.jp
Sun Jan 22 12:13:08 CET 2017
Phil and Mike, Thanks for your pointers -- both look like they
will work. Also in continuing to poke around the web, I also
found this function that works:
function qrtHTTP_FileExists pURL
local tSocket, tPath, tHeaders, tCommand
set the itemDelimiter to "/"
-- extract host IP address and file path from the URL
put item 3 of pURL into tHost
if tHost contains ":" then
put tHost into tSocket
put tHost & ":80" into tSocket
put "/" & item 4 to -1 of pURL into tPath
-- build the command
put "HEAD" && tPath && "HTTP/1.1" into tCommand
-- build the http headers
put "Connection: Close" & CRLF & \
"Host:" && tHost & CRLF & \
"User-Agent: Revolution (" & the version & ")" into tHeaders
-- open the socket, write he request and read the response
open socket tSocket
write tCommand & CRLF & tHeaders & CRLF & CRLF to socket tSocket
read from socket tSocket until CRLF
put word 2 of it into tResultCode
close socket tSocket
-- return our interpretation of the result code
return (tResultCode = 200)
It's working for me.... but now I can't re-find it so I can't
credit whoever wrote it!
Copying here for posterity!
On 2017.01.22, 19:09, Mike Bonner via use-livecode wrote:
> If you have php on your second server, and don't have lc, you can do a
> check with php similar to what you're talking about. This is untested but..
> If you have the following php file (perhaps named checkforfile.php) on the
> alternate server, and send it a get request containing the path to the file
> youre looking for, it will return true or false if it exists. This is
> obviously an extremely bare example. You'd want to make sure the get
> contains "myfile" and handle that too, as well as any other issues. In
> addition, you would probably want to limit the requests to only allowed
> areas and file types in the php script.
> echo file_exists($_GET["myfile"]);
>>From the lc side of things you could do something like this..
> get url "
> if it is true then
> put "<audio src=http://my.programserver.com/theFile.mp3>"
> put "program not found."
> end if
> Of course if you DO have lc on the program server you can do the same type
> of check and "put" true or false just like you did with php. (Also can be
> On Sun, Jan 22, 2017 at 2:16 AM, Phil Davis via use-livecode <
> use-livecode at lists.runrev.com> wrote:
>> Hi Tim,
>> Here is a very simplistic way of checking for a file on your server. It
>> assumes your mp3 files are in a 'programs' folder that resides in the
>> 'document root' folder. This script as it is here would be in a .lc file on
>> your server. You pass it a filename in the url and it tells you if the file
>> is in the programs folder or not.
>> So the url would look something like this:
>> The text of the 'check.lc' file:
>> set the errorMode to "inline"
>> put $_SERVER["QUERY_STRING"] into tFilename
>> put $_SERVER["DOCUMENT_ROOT"] & "/programs/" & tFilename into tPath
>> if there is a file tPath then
>> put "Found file" && q(tFilename)
>> put "Did not find file" && q(tFilename)
>> end if
>> function q pString
>> return quote & pString & quote
>> end q
>> This is most likely not exactly what you need, but maybe it'll give you a
>> starting point.
>> Thanks -
>> Phil Davis
>> On 1/21/17 11:36 PM, Tim Selander via use-livecode wrote:
>>> On-rev.com hosting, using LC server to present a list of our AM/FM radio
>>> programs for people to listening to on-demand.
>>> Out of a month's 20 programs, 3 or 4 might not get uploaded due to
>>> copyright issues, etc. Also, mp3's are not on the on-rev.com server, but
>>> another hosting service we use as well.
>>> Filenaming is standardized, so I know the list of programs. I want to hit
>>> the server, if the mp3 files exists, present it as an <audio src=, if the
>>> mp3 file does not exists, present a "Sorry, program not available" message.
>>> If I wanted to check on the existence of a small text file, it would be
>>> fast enough for me to just get it, put it into a variable and see if the
>>> variable has anything in it. But mp3's are too big, so too slow.
>>> Locally, I would simply write "if there is a file 'filename'..." --
>>> what's the equivalent command for checking on existence of a file on a
>>> Thanks in advance.
>>> Tim Selander
>>> Tokyo, Japan
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your
>>> subscription preferences:
>> Phil Davis
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
More information about the use-livecode