• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

Simple for Points! Saving in another directory....

Here's the scoop:

# ***** I create new file *****
open (NEW_FILE, ">myfile.csv") || die "Can't find database\n";
close (NEW_FILE);

# ***** I write in new data *****
open (FILE2,">>myfile.csv") || die "Can't find database\n";
print FILE2 "$affiliate,$fullname,$email,$date\n";
close (FILE2);

This saves file into the cgi-bin directory, how do I save in another directory?
current for create/save: http://www.mydomain.com/cgi-bin/myfile.csv
want for create/save: http://www.mydomain.com/files/myfile.csv
0
precision
Asked:
precision
  • 3
1 Solution
 
toschCommented:
open(FILE,">../files/myfile.csv") || die "unable to open myfile.csv for writing, stopped";

or give a an absolute path:
open(FILE,">home/www/www.mydomain.com/web/files/myfile.csv") || die "unable to open myfile.csv for writing, stopped";

can be the structure of the URL does not map 1:1 to the file system on your server machine (if apache is configured using directory aliases for example).

in case you have a structure like

$HOME/cgi-bin
$HOME/html

http://www.mydomain.com/somefile.html mapping to $HOME/html/somefile.html

and

http://www.mydomain.com/cgi-bin/somescript.pl mapping to $HOME/html/somescript.html

you will have to use ../html/files.myfile.csv in the first example.
0
 
toschCommented:
ooops.
there`s a slash missing in the second example:

open(FILE,">home/www/...

must be

open(FILE,">/home/www/...
0
 
precisionAuthor Commented:
Also...two more quick questions...

1)  clicking on myfile.csv opens the file in the browser, how can I force to have the client the option of "save" or "open"?

2)  Before I write data to file, I want to be sure that no characters are "," to avoid corrupting the database file, script for within perl.

Thanks...G
0
 
toschCommented:
1)

i'm not to sure if you can at all ( this means i don't know if the browser reacts to the Content-type send in the http header or to the extension "csv" - in the first case you might be able to reconfigure the mime types on your web server - in the second case you simply can't)

2)

what do you want to do with the ',' - character ?
delete them ? escape/replace them ?

search-replace is done like this in perl:

$a="foo bar baz foo bar baz foo bar baz";
$a=~ s/bar/bah/g;

# $a is now "foo bah baz foo bah baz foo bah baz"
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now