Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How do I delete temporary upload files?

by barbie (Deacon)
on Oct 19, 2003 at 10:54 UTC ( #300369=note: print w/ replies, xml ) Need Help??


in reply to How do I delete temporary upload files?

This is something I've noticed on occasions when using IIS on Windows. However, the files are created in a temporary folder that gets automatically cleaned periodically, so I don't worry about it. However, it has crossed my mind to figure out was causing it, but seeing as it seemed to happened only when using IIS, I'd just assumed that M$ had not implemented a clean up. If you're using another web server/OS, I'd be interested to know.

--
Barbie | Birmingham Perl Mongers | http://birmingham.pm.org/


Comment on Re: How do I delete temporary upload files?
Re: Re: How do I delete temporary upload files?
by Corion (Pope) on Oct 19, 2003 at 11:03 UTC

    A general thing with files under Windows is, that they can't be deleted as long as they are open. So it might be useful to close the filehandles to the temporary files before trying to delete them. I don't know whether this applies here though.

    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
      i wrote the script... apache web server, files are being created in the windows(98) directory that the script resides in... heres part of the code...
      if ($Data[3] eq "recieve") { $Data[11] = $fHandle->upload($Label[11]); $Data[12] = $fHandle->upload($Label[12]); if ((length($Data[11]) > 4)&&(lc(substr($Data[11],length($Data[11]) + - 4)) eq "\.jpg")) { open (FULLSIZE, ">".$Root."/records/classifieds/fullsize/".$Data +[2]."/".$Data[10]."\.jpg"); binmode(FULLSIZE); while (read($Data[11], $fBuffer, 1024)) {print FULLSIZE $fBuffer +} close (FULLSIZE); if ((length($Data[12]) > 4)&&(lc(substr($Data[12],length($Data[1 +2]) - 4)) eq "\.jpg")) { open (THUMBNAIL, ">".$Root."/records/classifieds/thumbnail/". +$Data[2]."/".$Data[10]."\.jpg"); binmode(THUMBNAIL); while (read($Data[12], $fBuffer, 1024)) {print THUMBNAIL $fBu +ffer} close (THUMBNAIL); goto RecieveDone; } copy($Root."/records/classifieds/fullsize/".$Data[2]."/".$Data[1 +0]."\.jpg", $Root."/records/classifieds/thumbnail/".$Data[2]."/".$Dat +a[10]."\.jpg"); } RecieveDone: $Data[11] = $Data[12] = ""; @Data = sub::clearcarry(0,@Data); @Data = sub::pushcommand("preview",@Data); goto AllDone; }


      you mean there's any easier way?

        Your code is very confusing, you should not name a namespace sub, and you should give your variables more meaningfull names than @Data!

        I also suspect that it is possible to pass you in filenames for the images such as ..\..\..\..\..\..\..\autoexec.bat\0 to overwrite your autoexec.bat file - you should use taint mode on your CGI scripts! Also, you should give out your own names (like 000000.jpg) instead of trusting on anything that a user supplies.

        From what I understood of the code, you open the files (via $fHandle->upload()), but you never close either $Data[11] or $Data[12]. Try closing them and the temporary files should be deleted automatically.

        I tried to rewrite your code a bit to make it clearer to me, but I couldn't test it:

        my $mode = $Data[3]; my $user = $Data[2]; my $imagename = $Data[10]; if ($mode eq "recieve") { my ($name_fullsize,$name_thumb) = ($Label[11],$Label[12]); my $fh_fullsize = $fHandle->upload($name_fullsize); my $fh_thumb = $fHandle->upload($name_thumb); if ($fh_fullsize =~ /\.jpg$/i) { open (FULLSIZE, ">".$Root."/records/classifieds/fullsize/$user/$ +imagename.jpg"); binmode(FULLSIZE); while (read($fh_fullsize, $fBuffer, 1024)) {print FULLSIZE $fBuf +fer} close (FULLSIZE); close $fh_fullsize; if ($fh_thumb =~ /\.jpg$/i) { open (THUMBNAIL, ">".$Root."/records/classifieds/thumbnail/$u +ser/$imagename.jpg"); binmode(THUMBNAIL); while (read($fh_thumb, $fBuffer, 1024)) {print THUMBNAIL $fBu +ffer} close (THUMBNAIL); } else { copy($Root."/records/classifieds/fullsize/$user/$image +name.jpg", $Root."/records/classifieds/thumbnail/$user/$imagename.jpg +"); } # $Data[11] = $Data[12] = ""; @Data = sub::clearcarry(0,@Data); @Data = sub::pushcommand("preview",@Data); goto AllDone; }
        perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://300369]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (18)
As of 2014-11-26 16:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (172 votes), past polls