codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Unlink  daithimcc at 08:31 on Friday, December 07, 2007
 

I have very little experience of Perl! I have been trying to delete a file using a script and it is refusing to go. One script creates the temporary file (empty) and later another is to delete it.
The url passes a parameter to the script: e.g. dfile.pl?f=abcde
The filename f obviously varies.

In the script:
$thef=param('f');
$ful="../../alpha/tempf/".$thef;
unlink($ful);


refuses to delete the file (e.g. abcde). When I manually enter:
unlink("../../alpha/tempf/abcde"); it goes. (It has nothing to do with file permissions).

Also I can test if the file exists, using the variable, -e $fnmi and I get true.

I would be very grateful if someone could suggest what the problem is here!



  Re: Unlink  mimir at 14:40 on Saturday, December 08, 2007
 

make sure that $thef and $ful contain what they are supposed to contain.

either with a debugger or simply by changing the script to the following:

$thef=param('f');
$ful="../../alpha/tempf/".$thef;

print STDOUT "The filename was: $thef\n";
print STDOUT "The full path was: $ful\n";

unlink($ful);




I also recommend using more descriptive and clear names like, $filename and $path and $path_and_file.



  Re: Unlink  daithimcc at 20:28 on Saturday, December 08, 2007
 

Thanks, yes everything was as it was supposed to be in the strings. I had narrowed it down to simply the use of the parameter. I have since learned how to read the error log on the server(!) and it told me the problem. I had a -T switch in the script. Apparently this is 'taint mode' and it realised that a parameter from outside was being used to delete a file and it disallowed it. The quick fix was to remove the -T switch, but now I'm playing around with regular expressions to try to validate the parameter and hopefully I'll be able to restore the -T switch.
Thanks again.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: Unlink
•  Call report done with Crystal Report 9 with Visual Basic 6.0
•  Call report done with Crystal Report 9 with Visual Basic 6.0
•  Call report done with Crystal Report 9 with Visual Basic 6.0
•  Re: partial string sorting of arrays
•  Passing Multiple Values from a child window to parent window
•  Re: inserting values from pop up
•  jumping to a different web page
•  Re: Page Load is getting called twice


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007