Gossamer Forum
Home : General : Perl Programming :

A script that deletes?

Quote Reply
A script that deletes?
Hi

Basically, I need a script that can delete a catalog.
I have a shopping-basket program, that temorary stores orders in a file. But the files will not be deleted from itself, and I want to delete a spesific catalog, as simple as possible, from browser.
Quote Reply
Re: A script that deletes? In reply to
There is a user of Gossamer script that has written a simple delete script. If I can find the Thread or author, I will post it here.

Found it! It is Pash1, the user, and you can find the delete script at the following URL:

http://find.virtualave.net

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited September 27, 1999).]

[This message has been edited by Eliot (edited September 27, 1999).]

[This message has been edited by Eliot (edited September 27, 1999).]
Quote Reply
Re: A script that deletes? In reply to
Hi

It worked (the one that delete the whole file)!

Just two questions...
1.Is it possible to get the script running without the question about I should "Open it from current...."/ Save file" ?
2.Is it possible to just insert it into anoter cgi-script (just remoing perl-path?), so that when a person push a link/button, the file is deleted??

Thanks for the script!
Quote Reply
Re: A script that deletes? In reply to
Eliot,
I've moved to my new site: http://www.cellwarp.com

The script that you were talking about was in two verions:

Code:
#!/usr/bin/perl
#
# +------------------------------------+
# | Simple File Cleaner 1.0 (Freeware) |
# | by Pasha Golovko |
# | cgi4free@find.virtualave.net |
# | http://find.virtualave.net/ |
# +------------------------------------+
#

$file = "software.db";

#
# +--------------------------------+ #

open(FILE, ">$file");
print FILE "";
close FILE;
print "Content-type: text/plain\n\n";
print "Done!";

and

Code:
#!/usr/bin/perl
#
# +------------------------------------+
# | Simple File Cleaner 1.1 (Freeware) |
# | by Pasha Golovko |
# | cgi4free@find.virtualave.net |
# | http://find.virtualave.net/ |
# +------------------------------------+
#

# +--------------------------------+ #

$file = "software.db";
$emailto = "cgi4free\@find.virtualave.net";
$emailfrom = "cgi4free\@find.virtualave.net";
$mailprog = "/usr/sbin/sendmail";

# +--------------------------------+ #

print "Content-type: text/plain\n\n";
open(DATABASE, "$file");
@entries = <DATABASE>;
open(MAIL,"|$mailprog -t");
print MAIL "To: $emailto\n";
print MAIL "From: $emailfrom\n";
print MAIL "Subject: The data from $file file has been deleted!\n\n";
print MAIL "$file\n\n";
print MAIL "\n\n";
foreach $line (@entries) {
print MAIL "$line\n";
}
close (MAIL);
close DATABASE;
open(FILE, ">$file");
print FILE "";
close FILE;
print "Done! You should receive $file in your $emailto mail account within 5 seconds or 6 hours (it depends on your mail server configuration).";

Neither of these scripts delete the file -- they clean the contents of it.
To delete the file using my web browser I would use this:
Code:
#!/usr/bin/perl
use CGI;
$in = new CGI;
$file = $in->param('file');
unlink ($file);
print "Content-type: text/plain\n\n";
print "$file was deleted!";
...and use it as:
http://www.server.com/cgi-bin/thisscript.cgi?file=/full/path/to/file.txt

Am I right? Smile

Best regards,

Pasha

------------------
www.cellwarp.com
Quote Reply
Re: A script that deletes? In reply to
You could possibly add Pasha1 codes as a sub-routine like sub delete_file. Just add the codes in between the following codes:

Code:
sub delete_file {
#------------------------------------------
# Delete file

CODES
}

Then you can create a Form variable known as "delete" and then set it for "Yes/No". You could add the following codes within the main part of your script:


Note: 1 = Yes
2 = No

Code:
if ($in{'delete'} eq "1") {
&delete_file;
}
if ($in{'delete'} eq "2") {
print qq|File not deleted.|;
}

Then in your form, you can add the following codes to create radio buttons for the variable, "delete":

Code:
<input type="RADIO" name="delete" value="1"> Yes
<input type="RADIO" name="delete" value="2"> No

Hope this helps.

Regards,


------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: A script that deletes? In reply to
I forgot to add:
You must delete or at least rename this script when you don't use it. It is VERY dangerous to leave such script on your web site! I think you know why Smile

Best regards,

Pasha

------------------
www.cellwarp.com