I have a script that allows the user to upload images to the server & writes the file name to a flat file DB.
I have another script that allows the user to delete the image entry from the DB.
Is there a way to also delete the image from the server folder as well?
Here is the script I am using to delete the entry in the DB:
[CODE=perl]
if ($input{'action '} eq 'delete'){
open (dbk,">$dbk");
@DB = <dbk>;
foreach $rec (@ODB){
chomp($rec);
($nktype,$nkcod e,) = split(/\,/,$rec);
if ($nktype eq $input{'nktype' } && $nkcode eq $input{'nkcode' }) {
print dbk "";
} else {
print dbk "$nktype,$nkcod e,\n";
}
}
close (dbk);
}[/CODE]
I know that possibly it is the 'unlink' function would do it, but how would I incorporate it into this code?
I tried this:
[CODE=perl]
$dbk='/home/mysite/db/dbp.txt';
$loc='/home/mysite/www/toypics/';
if ($input{'action '} eq 'delete') {
open (dbk,">$dbk");
@DB = <dbk>;
$file = '$loc$nktype';
foreach $rec (@ODB) {
chomp($rec);
($nktype,$nkcod e,)=split(/\,/,$rec);
if ($nktype eq $input{'nktype' } && $nkcode eq $input{'nkcode' }) {
unlink($file);
print dbk "";
} else {
print dbk "$nktype,$nkcod e,\n";
}
}
close (dbk);
}[/CODE]
thanks
Paul
I have another script that allows the user to delete the image entry from the DB.
Is there a way to also delete the image from the server folder as well?
Here is the script I am using to delete the entry in the DB:
[CODE=perl]
if ($input{'action '} eq 'delete'){
open (dbk,">$dbk");
@DB = <dbk>;
foreach $rec (@ODB){
chomp($rec);
($nktype,$nkcod e,) = split(/\,/,$rec);
if ($nktype eq $input{'nktype' } && $nkcode eq $input{'nkcode' }) {
print dbk "";
} else {
print dbk "$nktype,$nkcod e,\n";
}
}
close (dbk);
}[/CODE]
I know that possibly it is the 'unlink' function would do it, but how would I incorporate it into this code?
I tried this:
[CODE=perl]
$dbk='/home/mysite/db/dbp.txt';
$loc='/home/mysite/www/toypics/';
if ($input{'action '} eq 'delete') {
open (dbk,">$dbk");
@DB = <dbk>;
$file = '$loc$nktype';
foreach $rec (@ODB) {
chomp($rec);
($nktype,$nkcod e,)=split(/\,/,$rec);
if ($nktype eq $input{'nktype' } && $nkcode eq $input{'nkcode' }) {
unlink($file);
print dbk "";
} else {
print dbk "$nktype,$nkcod e,\n";
}
}
close (dbk);
}[/CODE]
thanks
Paul
Comment