in reply to unlink($ful) does not delete

First, on perlmonks.org you use HTML-ish markup, not BBCode.

You should always check for success of your operations:

unlink($ful) or die "Can't delete '$ful': $!";

From the looks of the param function it looks like you are writing a CGI script, which means it probably runs under the user www or something similar, and might not have the privileges to delete the file anyway.

BTW I hope you're aware that what you do might be a security risk.

Replies are listed 'Best First'.
Re^2: unlink($ful) does not delete
by daithimcc (Novice) on Dec 07, 2007 at 17:08 UTC
    Sorry, but I don't know what the first remark means. Yes I am uploading this to my website and to test it, running it from my browser's address bar. So I type in www.mydomain.com/.../test.pl?f=sdfkjkkk which is then supposed to delete the file (the file name will not be immediately what f= as I realise this would be a major security risk, but it is at the moment until I can get this thing to work)! The reason I said it wasn't a priveleges problem is that when my uploaded script contains the filepath typed directly "../../alpha/abcde" it does delete but when I use $ful it does not - so they both have been run the same way. I am grateful for any help.
      The important point is that your code should check whether the file deletion has succeeded, and that if it has failed it should print an error message.
      $thef=param('f'); $ful="../../alpha/tempf/".$thef; unlink($ful) or die "Couldn't unlink($ful): $!";
      The error message will show up in your webserver's error log. If the filename printed is what you expect it to be, and you can't work out from the error message what the actual problem is, we can help you with that. But you will have to tell us what the error message is.
        Thank you that solved it for me! I thought the error was to appear on screen. I spent so much time working at this.
        The error I got for your line was:
        Insecure dependency in unlink while running with -T switch at dfl.pl line 42.
        What exactly this means or why I had the -T switch on in the first place I don't know, but I removed it and my file disappeared!!
        If you know offhand what this all means I would like to hear but many thanks!
        David
      • Posts may use any of the Perl Monks Approved HTML tags: a, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul.
      • See Writeup Formatting Tips and other pages linked from there for more info.