[ back to toc ]

Unlink cannot delete my files....

Date: 2002/03/18 11:36

Q:
Dear sir,
I m really confused why my perl code is not deleting files from a
directory. I a, using a script which sends email with attachments, so at
first it uploads the attached files in a folder name "uploaded". Then
after sending the email, i wish to clean up the folder but it is not
deleting the files, I have cheked the directory path...eveyrthing is ok.
Moreover, I am not getting any Internal Server Error, it seems that my
script has deleted the files, but when i check that folder using FTP, I
see that ,still the files are there.

In view of the fact mentioned above, would you be kind enough to help me
finding out the problem..

Thanks and regards,
*NAME-DELETED* Hussain.

I have attached the sub routine which deletes the files.
I have set permission 777 in that uploaded folder. Moreover, I have placed
a print statement for debugging purpose just before the line which
contains unlink statement. And i see that it is printing correctly. So
whats the problem...i can't find out.

sub mail_sent {
# mail has been sent, so lets clean up (delete temp attachments etc...)
open(CF, "attach.txt");
@all = <CF>;
close(CF);
open(DATAFILE,">attach.txt");
for ($i = 0; $i<=$#all; $i++) {
print qq[\n DELETING : $upload_dir/$all[$i]];
unlink "$upload_dir/$all[$i]" ;
}
open(DATAFILE,">email.txt");
print DATAFILE ""; # set file to 0
close(DATAFILE);
open(DATAFILE,">attach.txt");
print DATAFILE ""; # set file to 0
close(DATAFILE);
print "Your email has been sent.";
}

A:
I do not know what is contained in the file attach.txt, but I assume that
there are several file names. However I doubt that your real file names
end with a \n in the directory. On the other hand $all[$i] most probably
has.

chomp @all;

after reading the array.

Regards,
Peter

[ back to toc ]