LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-12-2006, 08:17 AM   #1
anroy
LQ Newbie
 
Registered: Aug 2006
Location: Tokyo
Distribution: Gentoo, Xandros
Posts: 18

Rep: Reputation: 0
Perl/CGI uploader program - temp file not getting deleted


I have a Perl CGI program to upload zipped files to a server directory.

A temporary file is created in the /var/tmp/ directory. From my Googling I have learned that this file is supposed to get deleted automatically.

In my case this is not happening, hard disk space is getting squeezed. My client had the system up for over a month and they suddenly ran out of disk space. That is when I got the call.

The uploading itself is working fine.

The environment is Apache running on Linux.

My questions:

1) What could possibly be causing this? Is there a setting somewhere, either in CGI, or Apache, or in the OS?

2) If the cause cannot be determined, how do I delete this each time the upload finishes?

Question 1 is the more important of the two. I would rather know the root cause and tackle that, than apply a bandaid solution.

Here is my code.

Form
Code:
<form action="do_upload.cgi" enctype="multipart/form-data" method=POST>
<input type="hidden" name="MAX_FILE_SIZE" value="10000000">
<input type="hidden" name="action" value="DoUpload">
Select file  <input type="file" name="uploadFile" size="32"><br>
<input type="submit" value="Upload!">
</form>
Uploader code
Code:
#!/usr/bin/perl
use strict;
use CGI ':standard';

my $dirName = "ZIPData";
my $uploadFile = param( 'uploadFile' );

my @pathArr = split( /\\/, $uploadFile );
my $pathEltCnt = scalar( @pathArr );
my $fileName = $pathArr[$pathEltCnt-1];

# various validation here

open ( UPFILE, "> $dirName/$fileName" ) || die("Cannot open($fileName): $!");
binmode( UPFILE );
my ( $data, $chunk );
my $fileSize = 0;
while ( $chunk = read ( $uploadFile, $data, 1024 ) ) {
	print UPFILE $data;
	$fileSize += $chunk;
}
close ( UPFILE ) || die("Cannot close($fileName): $!");
Thanks!
 
Old 09-12-2006, 10:29 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
AFAIK, this 'automatic' cleaning is normally performed by a cron job, possibly running tmpwatch or some similar tool. Are you sure this is running? Is it running frequently enough? You will need to find a balance between how long to leave the files on the temporary directory, and how long they are required for your application.

--- rod.
 
Old 09-13-2006, 01:09 AM   #3
anroy
LQ Newbie
 
Registered: Aug 2006
Location: Tokyo
Distribution: Gentoo, Xandros
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by theNbomr
AFAIK, this 'automatic' cleaning is normally performed by a cron job, possibly running tmpwatch or some similar tool. Are you sure this is running? Is it running frequently enough? You will need to find a balance between how long to leave the files on the temporary directory, and how long they are required for your application.

--- rod.
OK, I had no idea that this was the case. I was under the impression that it gets deleted automatically after I do the close ( UPFILE ).

If it is a cron job scheduled by the system administrators then I would have no control over that as it is my client's site. And they use a large commercial hosting company so they would have nothing to do with it either.

So I guess I should definitely delete it myself. I am not sure how to though, the unlink command requires a file name. Does anyone know how to determine the file name of this temp file at runtime? It seems to be "CGI" with a string of digits appended to it, different each time.
 
Old 09-13-2006, 01:45 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well, surely this is your filename: $dirName/$fileName ?
iirc, if you unlink the file after you open it (but before you close it), in the same prog, the file will continue to exist until you close it, at which pt it will 'auto-magically' get deleted ie unlinked.
 
Old 09-13-2006, 02:33 AM   #5
anroy
LQ Newbie
 
Registered: Aug 2006
Location: Tokyo
Distribution: Gentoo, Xandros
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by chrism01
Well, surely this is your filename: $dirName/$fileName ?
No, that is the destination file, the result of the upload. I certainly don't want to delete that!

Just to make sure, I tried it and that was indeed the case. It has nothing to do with the temporary file.

Edit: By the way I am not using the object-oriented CGI.pm, like this line:
$tmpfilename = $query->tmpFileName($filename);

I am not sure it is available to me.

Last edited by anroy; 09-13-2006 at 02:37 AM.
 
  


Reply

Tags
cgi, perl, upload



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Call a C program from Perl CGI Script anoop_cn Programming 1 05-11-2004 04:37 PM
cgi perl : I cant get perl to append my html file... the_y_man Programming 3 03-22-2004 05:07 AM
Total Newbie... Perl program install help for CGI::KWIWI futuremed Linux - Newbie 0 02-29-2004 11:14 AM
Executing a program on server using CGi/PERl ?! avios Red Hat 1 12-29-2003 02:34 AM
Gtk gui on a cgi perl program bruce1271 Linux - Software 2 12-08-2003 05:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration