Page 1 of 1
libURLDownloadToFile follow php redirect?
Posted: Tue Oct 26, 2010 9:59 pm
by cborn
I'm using Rev/LiveCode to create an applet that is embedded into the pages of the course management system at our school. The CMS is Moodle, which is written in PHP. All links to media files are run through a file.php file, so a link to a file would be
https://mymoodlehost.edu/file.php/PathToActualFile
I'm trying to use libURLDownloadToFile to get one of these files and pull it into the applet, but I only get an empty file (0KB). Is it the case that this command cannot follow the redirects in the file.php? Is there a way to make it do that?

Re: libURLDownloadToFile follow php redirect?
Posted: Tue Oct 26, 2010 10:10 pm
by FourthWorld
libURLDownloadToFile is an FTP command, but the protocol in the URL you're using is HTTP.
Have you considered just using "get" and then writing what you get to a file? e.g.:
get url "
https://mymoodlehost.edu/file.php/PathToActualFile"
put it into url ("file:"& tMyLocalFile)
Re: libURLDownloadToFile follow php redirect?
Posted: Tue Oct 26, 2010 10:18 pm
by cborn
libURLDownloadToFile also speaks HTTP and HTTPS, according to the dictionary. I was able to use it from another static HTTP address without any problem whatsoever.
I did try what you suggested, and that also failed.
Re: libURLDownloadToFile follow php redirect?
Posted: Wed Oct 27, 2010 12:22 am
by FourthWorld
The URL works well in your browser?
Re: libURLDownloadToFile follow php redirect?
Posted: Wed Oct 27, 2010 2:15 pm
by cborn
Yes, it does, as long as I'm logged into the course management system in that browser. The file downloads without a hitch in that case. It's for that reason that i suspect the problem is more in the way Rev is trying to call the file and less to do with permissions of the server or CMS itself.
FWIW, I'm using Rev Enterprise 4.0.0 Build 950. I want to move to LiveCode, but cannot realistically do so until they release the revweb plugins compatible with that version.
Thanks for thinking about this, I very much appreciate the assistance. Please let me know if you have any other ideas on how to work around this.

Re: libURLDownloadToFile follow php redirect?
Posted: Wed Oct 27, 2010 5:09 pm
by FourthWorld
cborn wrote:Yes, it does, as long as I'm logged into the course management system in that browser. The file downloads without a hitch in that case.
Sounds like the server is expecting to authenticate the session but is unable to with your script. May require adding cookie support in your script; hard to say without knowing more about how the server and its login work.
If you have a port sniffer like Little Snitch you can log the transaction when you sign in and get the document from your browser, and that should provide good guidance for what's needed to emulate those browser behaviors in your script.
Re: libURLDownloadToFile follow php redirect?
Posted: Wed Oct 27, 2010 9:30 pm
by cborn
Richard,
Thanks for this tip, I managed to get the cookie info into a GET request and got it working!

Re: libURLDownloadToFile follow php redirect?
Posted: Wed Oct 27, 2010 11:51 pm
by FourthWorld
Excellent! Glad to hear it.