Welcome, Guest. Please login or register.
Did you miss your activation email?
05/21/12, 03:12
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  Server side Scripting and Database Support
| |-+  PHP, Perl, ASP, JSP, CFM (Moderators: Flash-db, Musicman, vesa kortelainen, Ronald Wernecke, Jorge Solis, nothingGrinder)
| | |-+  PerlWriteVarsToText problem
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: PerlWriteVarsToText problem  (Read 5533 times)
bender
Server what's that
*
Posts: 24



View Profile WWW Email
« on: 02/05/02, 00:36 »

First off, thanks for replying to my email Jeff... much appreciated! Anyways, the problem I'm having is that when I hit the 'save' button in the .fla, the cgi
script returns a 'success' value back to the flash movie, but when I
return to the main menu and then enter the example again, the flash
movie reloads the text file, and for some reason the changes that I made
haven't been saved. I've also tried downloading the text file right from
the server (just to double check), and it hasn't been changed at all. I
don't really know much about Perl, but I'm pretty sure that the problem
I'm having is within the cgi script. I'm pretty sure I have the path to
the txt file right, because if I change it, the cgi script returns an
'error' message to flash saying that it can't find the file. I've got
the file permissions for the text file set to CHMOD 777 and the cgi
script is set at CHMOD 755. I've tried setting the permissions to a few
different settings, but that also didn't help. I dunno... I've been
playing around with this for quite some time now, and I can't figure out
why it's not working. Can anyone help me out?
I'm sure I'm just overlooking something simple...     thanks.
Logged
Flash-db
Administrator
Systems Administrator
*****
Posts: 1867



View Profile WWW
« Reply #1 on: 02/05/02, 05:12 »

Hey Bender,

I'm having trouble finding a reason why the script is not working.  From what you have mentioned it seems like it should be.  

One easy way to check that the script is ok.  Is to type in the complete URL in the browser to that script.  Then look on that page to see if their where any errors or the success message was printed out.

Also make sure that you have the
require "subparseform.lib";
&Parse_Form;
-- subparseform.lib  file located in your cgi-bin as well as the other file.

Then to make it easier, we can cut out the Flash movie part for testing.  

Change:
Code:

$Title = $formdata{'Title'};
$Contact = $formdata{'Contact'};
$About = $formdata{'About'};
$News = $formdata{'News'};
$Products = $formdata{'Products'};
$Link = $formdata{'Link'};

@New =  ("Title=$Title&Contact=$Contact&About=$About&Products=$Products&News=$News&Link=$Link");


To
Code:

$Title = "Some Test Title";
$Contact = "Some Test Contact";
$About = "About Test";
$News = "News Test";
$Products = "Products Test";
$Link = "Links Test";

@New =  ("Title=$Title&Contact=$Contact&About=$About&Products=$Products&News=$News&Link=$Link");


What we are doing here is hard-coding in Values so we can test if The file is writing to the Text File without having to worry about the Flash part.  If that is working their is a problem with the Variables going from the Flash Movie to the CGI script - if that's the case I'll go into that later.
Logged

-Jeff.
Musicman
Administrator
Systems Administrator
*****
Posts: 2685



View Profile WWW Email
« Reply #2 on: 02/05/02, 12:20 »

Hi,

I have checked some very similar code today which failed due to writing to a weird location.
Basically, it is this:
you have a movie in your webroot, say test.swf
the movie may want to read saved vars back from the text file, so your text file is in the web root as well.
Your script is in the cgi directory, so it wants to save to a different place...
As a rule of thumb: if you access your website through ftp, and there are two folders, like www and cgi-bin, try writing the file as
open TXT, ">../www/text.txt";
If the cgi-bin appears as a subdir of your webroot (unlikely), try ../text.txt
Of course, it is possible to have different directory mapping in ftp as well as for the webserver, but most server paths should work as I described it.

Musicman
Logged
bender
Server what's that
*
Posts: 24



View Profile WWW Email
« Reply #3 on: 02/05/02, 14:07 »

Alright! I got it working! Just a small oversight on my part. My problem was pretty much exactly what you mentioned Musicman. While I was trying out what Jeff had suggested, I noticed that when I ran the swf, that the cgi script automatically generated the text file inside of the cgi-bin folder. So now I had a copy of the text file in my root folder and another copy in the cgi-bin folder. I d/led the one in the cgi-bin folder and sure as sh*t it had all of the changes. So I realized that the path that was set in the cgi script (open (LOG, ">Ex2TextFile.txt") || &ErrorMessage;) was wrong (or right - depends how you look at it). It was creating the file in the cgi-bin (the same directory that I had the script in), and the swf was loading the text file that I had put into the root folder. So all I changed was the path in the swf file to:

loadVariablesNum ("http://www.******.ca/cgi-bin/Ex2TextFile.txt?Ran="+random(999), 0);

simple enough! I don't know how I overlooked this. I was pretty sure that I had originally set it up like that. Oh well. It's working now!

Thanks a ton to both Jeff and Musicman for their suggestions/replies and an extra thanks to Jeff for creating an excellent tutorial/example! Oh yeah - one more thing - this forum is great! The moderators seem to be a hell of alot more helpful than any other board I've been in! Keep up the good work and hopefully I can help contribute to the boards!

Cheers
Logged
Musicman
Administrator
Systems Administrator
*****
Posts: 2685



View Profile WWW Email
« Reply #4 on: 02/05/02, 14:36 »

Hi,

one more comment on that: _you_ have been lucky - many servers just do not let you open plain files from the cgi area. The reason for this is fairly obvious: say you have a bigger project involving many scrips - there might be a common include file (not named *.cgi because it is not meant to be run as script) that describes paths on the server, database passwords and similar stuff.
There may also be your own secret text files like a list of passwords.
So some servers just protect you by denying access to such files, some do nothing, and some provide storage outside of web and cgi folders for that purpose.
Since changing access rights is not that helpful (it is the server process reading and writing these files), a server should either deny access or offer outside storage - the latter means that you may have to make massive edits on existing script packages
Unfortunately some servers dont allow to write outside the cgi folder - in this case the only rescue is to use another script to read the text file. This has the added advantage that you can add anti-caching headers to the read script

Musicman
Logged
bender
Server what's that
*
Posts: 24



View Profile WWW Email
« Reply #5 on: 02/05/02, 19:01 »

 lol... you know what? I think I just encountered that problem. (I think). It seems to work fine with IE, but when I use Netscape, the main movie that actually loads the txt file (not the PerlWrtieVarsToText one), doesn't seem to want to load it. I'm not sure if it's just a problem with the 'refreshing' or what, but even when I clear out the cache, it still seems to not work. Now I'm sure if it was a problem with the server not allowing this, then it shouldn't work in IE right? Mmmmm....
I should be able to store this txt file in the root folder right? Would this solve my problem? If so, what would I have to enter as the path to make this work? (I think this was my original problem - I had the path to the root folder wrong) This is how I currently have the path setup when the txt file is in the cgi-bin folder:

open (LOG, ">Ex2TextFile.txt") || &ErrorMessage;

Thanks again...
Logged
Musicman
Administrator
Systems Administrator
*****
Posts: 2685



View Profile WWW Email
« Reply #6 on: 02/05/02, 20:20 »

Hi,

as I said before, have a look at how your ftp client displays the web server. If you have cgi-bin inside the web root, you would use ../Ex2TextFile.txt
If you have www (or html, or whetever) next to each other, try ../www/Ex2TextFile.txt
There is no IE / Netscape dependency there
What about a read script, call it http://yoursite.com/cgi-bin/read.cgi?
#!/usr/bin/perl
print "Content-type: form/x-www-urlencoded\n\n"; ## btw: flash does not care for type
open F, "Ex2TextFile.txt";
while(<F>) { print; }
If you still experience problems, please show url to the movie

Musicman
Logged
bender
Server what's that
*
Posts: 24



View Profile WWW Email
« Reply #7 on: 02/06/02, 01:29 »

okay,... got it sorted all out. Thanks again. But now you have me curious about the read script. I'm a complete Perl n00b, but I can see how knowing how that read script works would come in handy down the road. I would love to learn how it works. (I can sorta figure it out by looking at it...).  Could you suggest a good book, or a good website that would be a good starting place for learning Perl? It doesn't really seem much different from flash actionscript (sorta).

#!/usr/bin/perl
print "Content-type: form/x-www-urlencoded\n\n";
open F, "Ex2TextFile.txt";
while(<F>) { print; }

Cheers
Logged
Musicman
Administrator
Systems Administrator
*****
Posts: 2685



View Profile WWW Email
« Reply #8 on: 02/06/02, 03:35 »

Hi,

you should probable read the "camel" book - there is also another book from that series specifically for web applications, but I have not read that

Musicman
Logged
bender
Server what's that
*
Posts: 24



View Profile WWW Email
« Reply #9 on: 02/06/02, 09:24 »

I will try and hunt it down. Thanks.
Logged
bender
Server what's that
*
Posts: 24



View Profile WWW Email
« Reply #10 on: 02/07/02, 01:48 »

Geez....    I dunno what's going on, but now I can't get it to work again. If I put the .txt file into the cgi-bin folder, the main movie can't read it. If I take it out and put it in the root folder, the main flash movie reads the text, but the PerlWriteVarsToText movie won't work. The script says it can't find the text file. If I enter the URL for the script like Jeff suggested, it returns the failed connection - can't find text file error. Here is how I have the path in the UpdateVars.cgi file set:

open (LOG, ">http://www.***.ca/n*****k/n*****k.txt") || &ErrorMessage;

my cgi-bin folder is setup like this:

http://www.***.ca/n*****k/cgi-bin

I have a cgi-bin folder in the root directory, and then I created another one (the one listed above) inside of the 'n*****k' folder to use as a test. Would this affect anything? I don't think so though... just thought I should mention it - just in case...

So I'm not sure if I just have the wrong path set, or if my server won't let the script access the text file because it's outside of the cgi-bin folder. *note - the permissions for both the txt file and the cgi file are set to CHMOD 777 & 755 respectively.

Is there another way of doing this? Should I maybe try putting the txt file back into the cgi-bin folder? What about the 'read' script that Musicman suggested? How would I go about implementing that if I had to?

Thanks for your patience...

Cheers
Logged
Musicman
Administrator
Systems Administrator
*****
Posts: 2685



View Profile WWW Email
« Reply #11 on: 02/07/02, 13:23 »

Hi,

you are not going to overwrite a server but just a plain file
So the code should read
open LOG, ">/path/to/your/file"
no http, ftp, bullshit, nothing.
If the text file is inside the cgi folder, this is simply
open LOG, ">Ex2TextFile.txt"
BTW: only few servers allow scripts outside the cgi-bin folder, so making a "test" folder with a "cgi-bin" inside is no good idea
Using the read script - upload to the cgi-bin like the others and call, e.g. read.cgi - then change your movie to load variables from http://yoursite.com/cgi-bin/read.cgi

Musicman
Logged
bender
Server what's that
*
Posts: 24



View Profile WWW Email
« Reply #12 on: 02/07/02, 20:49 »

arrrgh,... I sent an email to the server admins to see if my problem is that the server isn't allowing me to write to a file that's outside of the cgi-bin folder.  I've tried every possible thing I could think of as a path , and without any luck. It has to be a problem with the server...    I tried moving everything so that the script was in the actual cgi-bin folder that is in the root directory, and then I put the txt file in the root directory and changed the path to open LOG, ">/file.txt", but this still won't work. I understand what I'm trying to do, and I pretty much understand the entire script, but I'm just having problems with the darn path. I know that I'm not going to 'overwrite a server'  :)

I'm gonna wait until I hear back from the admins, and hopefully they can tell me whether this is my problem or not.

About the read script - I know how to use it, but I was wondering if you could explain the script itself. I'm not sure how the x-www-urlencoded part is supposed to be setup. And what the 'F' is for. I'm guessing that it opens a file (Ex2TextFile.txt) and that the next line prints it (or reads it) while it's open?

#!/usr/bin/perl
print "Content-type: form/x-www-urlencoded\n\n";
open F, "Ex2TextFile.txt";
while(<F>) { print; }

But I'm also guessing that I'm probably gonna run into the same problem I'm having with the other script. I was thinking that I could call the read script from within the main movie, and have it load the text file from the cgi-bin into the main movie. Seeing as this seems to be the only way to get the text editor to work (by placing the .txt file into the cgi-bin folder with the read/write script).

I dunno...  

Logged
bender
Server what's that
*
Posts: 24



View Profile WWW Email
« Reply #13 on: 02/08/02, 02:12 »

k.... I think I got it this time. I found an interesting script which I ran and it helped me to find the actual path. Here's the script I found:

#!/usr/bin/perl
print "Content-type: text/html\n\n";
foreach $item (keys %ENV)
{ print "$item = $ENV{$item}<BR> \n"; }
$rundir=`pwd`;
print "Working Directory is: $rundir<BR>";

I saved it as diag.cgi and saved it in my cgi-bin folder. When I ran it, I noticed this amoung everything else:

Working Directory is: /home/sites/site***/web/cgi-bin

I never realized that the path would have all of this. I thought that at the most it would have the /web/cgi-bin, but not all of the other stuff.

Anyways, I changed my path in the script - and voila!
I just thought I would post this in case someone else is having the same problem.
Again, thanks for your hel guys!

Logged
Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
anything