Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically deleting file if it is too big

Status
Not open for further replies.

c4n

Programmer
Mar 12, 2002
110
SI
How can I delete a file using CGI if it becomes too large?

For instance: I have a file but don't want it to be larger than 10kb. If it reaches 10Kb the script should emtpy the file it and start writing data in now empty file.

Thanks in advance
 
First, the CGI process must have sufficient permissions
to play with the file. If it does, just check the size
of the file and either open it to append or open it to
write (overwrite).

Code:
#!perl
$file = 'some_file.txt';
$size = int((stat($file))[7]/1000);
print "File Size: $size K\n";

if ($size > 10) { open(HANDLE,">$file"); }
else { open(HANDLE,">>$file"); }
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Thanks, just what I need :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top