Forum


Replies: 5   Views: 3986
Deleting tmp files?
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by Squad internet  · 16-10-2012 - 12:14

Hi guys,

I'm almost done with my script, did quite some testing (generated over 200 files),... and I'm looking at my /tmp dir right now :(
How can I make this lib removing its tmp files after rendering?
Should be default behaviour right?

Tnx so far ;)

Posted by Squad internet  · 11-04-2013 - 12:13

require_once('/var/www/Core/0.1/Includes/phpdocx/classes/CreateDocx.inc');
class Tools_Docx extends createDocx{


/**
* Delete all tempfiles.
* MAKE SURE YOU USE A SEPATE DIRECTORY FOR PHPDOCX IN YOUR /TMP DIR!!!!
* This will DELETE all files in the directory you passed in the constructor!!!!
*
*/
public function cleanUp(){
$this->_recurseDelete($this->getTemporaryDirectory());
}

private function _recurseDelete($path){
if(is_dir($path)){
$dirs=scandir($path);
$c=count($dirs);
for($i=0;$i<$c;$i++){
if($dirs[$i]!='.'&&$dirs[$i]!='..'){
$this->_recurseDelete($path . DIRECTORY_SEPARATOR . $dirs[$i]);
}
}
if($path!=$this->getTemporaryDirectory()){
rmdir($path);
}
}else{
unlink($path);
}
}
}

Posted by admin  · 11-04-2013 - 12:13

Hello,

Each server should take care of temp files. I recommend you to do a cron task that delete them or use default config (on restart or depending on the disk space); but if you prefer to remove each temp file in CreateDocx class, just add this code:

unlink($this->_tempFile);

in line 4411. If you're using templates add this:

unlink($fileName);

after line 4587.

Regards.

Posted by Squad internet  · 11-04-2013 - 12:13

Hi,

Thanks for your reply, I allready created a for me (for now) valid solution, If it needs to be more specific I will change that later.

Btw: I do honestly disagree with your solution as I can't know from with the cron or one of those the temp files is used or not.
By that my server does NOT restart ;) ,.. and I can not use the default /tmp dir as this would have some security issues.
And finally: if I need to write cron-jobs for every script that creates tmp files,.. for every site that is beeing hosted....

:( I'll endup beeing a cron-programmer :(

However, thanks for your reply!

Posted by admin  · 11-04-2013 - 12:13

Hello,

Thanks for posting your solution, it's a good one. I just wanted to post my own solution.

Regards.