strikr has asked for the wisdom of the Perl Monks concerning the following question:

In my program the user can upload different types of files, and my program checks to see if that file is already on the server using -e $file, and if it is there it deletes it using unlink.

My problem is, if the file is found it does not delete it.

And if I go to the file directly through FTP and try to delete it manually it still does not delete.

Is this some sort of cache problem?

Any ideas would be helpful.
Thanks!

Replies are listed 'Best First'.
Re: Problems deleting a file.
by sauoq (Abbot) on Oct 16, 2002 at 19:25 UTC

    Use unlink or warn $!; and Perl might give you a hint as to why it isn't deleting the file.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Problems deleting a file.
by sschneid (Deacon) on Oct 16, 2002 at 19:17 UTC
    Who is the program running as? Does it have sufficient permissions to delete the file? Do you have an example of the script?

    It sounds like permissions problems to me, especially since you mentioned that you can't manually delete the file, either.

    scott.
Re: Problems deleting a file.
by Zaxo (Archbishop) on Oct 16, 2002 at 19:18 UTC

    Chances are it's a file or directory permissions problem.

    After Compline,
    Zaxo

      I checked the permissions and it has all the necessary permissions. Here is an example of the code, I'm probably way off first time trying to do something like this:
      $filekey = $cgi->param("doc_file"); unlink($filekey) if -e $pubFile_path$filekey; if ($filekey) { if ($filekey =~ /([^\/\\]+)$/) { $filename = $1; ($ext) = $filename =~ /(\.\w+)$/; } else { return "You attempted to upload <B>$filekey</B> that isn't properly fo +rmatted. Please rename the file on your computer, and attempt to uplo +ad it again. Files may not have forward or backward slashes in their +names. Also, they may not be prefixed with one (or more) periods."; } $path = $pubFile_path . "/" . $count . $ext; open(OUTFILE, ">$path") or &script_err("Unable to open $path \nReason +: $!");; binmode(OUTFILE); while ($bytes = read($filekey,$buffer,1024)) { $totalbytes += $bytes; print OUTFILE $buffer; } close(OUTFILE); }

        Include the full path to the file and it will work provided your script (generally user nobody) has sufficient rights. ALWAYS check your return values and you will ALWAYS (almost ;-) know why things don't work if they fail....

        my $fullpath = $webserver.$path.$to.$file; unlink $fullpath or dienice("Can't unline '$fullpath' Perl says the error is $!"); # with CGI let's avoid a 500 error sub dienice { print "Content-type: text/html\n\n" . shift; }

        You also have typo's in your post that will stop it working FWIW

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print