Home: Perl Programming Help: Intermediate:
saving files in Unix



jacksonpt
Deleted

Jul 19, 2000, 9:25 AM


Views: 642
saving files in Unix

I am working on a form that generates an HTML file. I want to be able to give users the ability to specify (via the form) where they want to save the file (relative or absolute) and under what name to file is saved. How can I dynamically save these files based on the user's input?

Thanks in advance,
Jackson


Cretep
User

Jul 19, 2000, 6:16 PM


Views: 642
Re: saving files in Unix

Hi
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


open (FILE, ">$path");
print FILE "$stuff";
close(FILE);
</pre><HR></BLOCKQUOTE>
Where $path contains the path to the file and $stuff contains the stuff you want to print into the file.


jacksonpt
Deleted

Jul 20, 2000, 4:02 AM


Views: 642
Re: saving files in Unix

OK, I guess I was not clear enough in what I am looking for. I want to have a user fill out a form, and then have a perl script that will dynamically create an HTML file based on the way the user fills out the form. 2 things that the user will have to provide when filling out the form are a file name under which the file will be saved, and a path to where the file will be saved. I want the user to be able to specify where the file will be saved, and what the file will be named.

Thanks again,
Jackson


Kanji
User

Jul 20, 2000, 7:33 AM


Views: 642
Re: saving files in Unix

Assuming Cretep's code and that you're using CGI.pm ...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

$path = param('path') . "/" . param('file');</pre><HR></BLOCKQUOTE>

Error checking and sesnisble defaults are left as an exercise to you. :-)

On a side note, what you're doing has huge security implications: what if someone chooses the same path and filename as the script itself? Ooops! I hope you have backups!