Skip to content
Snippets Groups Projects
Commit 77b51f03 authored by Robin Appelman's avatar Robin Appelman
Browse files

add temporary file managment

parent 76d7ce4b
Branches
No related tags found
No related merge requests found
......@@ -313,6 +313,9 @@ class OC{
// Last part: connect some hooks
OC_HOOK::connect('OC_User', 'post_createUser', 'OC_Connector_Sabre_Principal', 'addPrincipal');
OC_HOOK::connect('OC_User', 'post_deleteUser', 'OC_Connector_Sabre_Principal', 'deletePrincipal');
//make sure temporary files are cleaned up
register_shutdown_function(array('OC_Helper','cleanTmp'));
}
}
......
......@@ -26,6 +26,7 @@
*/
class OC_Helper {
private static $mimetypes=array();
private static $tmpFiles=array();
/**
* @brief Creates an url
......@@ -415,4 +416,28 @@ class OC_Helper {
}
return $count;
}
/**
* create a temporary file with an unique filename
* @param string postfix
* @return string
*
* temporary files are automatically cleaned up after the script is finished
*/
public static function tmpFile($postfix=''){
$file=tempnam(get_temp_dir(),'OC_TMP_').$postfix;
self::$tmpFiles[]=$file;
return $file;
}
/**
* remove all files created by self::tmpFile
*/
public static function cleanTmp(){
foreach(self::$tmpFiles as $file){
if(file_exists($file)){
unlink($file);
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment