createTempFile()

Description

Create a temporary copy of the file in the tmp folder (ie. the usual filestore/tmp/)

Parameters

ColumnTypeDefaultDescription
$path string File path
$uniqid string If a uniqid is provided, create a folder within tmp. See get_temp_dir() for more information.
$filename string Filename of the new file

Return

boolean|string Returns FALSE or the file path of the temporary file

Location

include/resource_functions.php lines 4059 to 4086

Definition

 
function createTempFile($path$uniqid$filename)
{
    if (
        !
file_exists($path)
        || !
is_readable($path)
        || !
is_valid_rs_path($path)
    ) {
        return 
false;
    }

    
$tmp_dir get_temp_dir(false$uniqid);

    if (
trim($filename) == '') {
        
$file_path_info pathinfo($path);
        
$filename md5(mt_rand()) . "_{$file_path_info['basename']}";
    }

    
$tmpfile "{$tmp_dir}/{$filename}";

    
$copy_hook hook('createtempfile_copy''', array($path$tmpfile));
    if (!
$copy_hook) {
        
copy($path$tmpfile);
    } else {
        
$tmpfile $copy_hook;
    }

    return 
$tmpfile;
}

This article was last updated 15th June 2025 07:35 Europe/London time based on the source file dated 5th June 2025 10:55 Europe/London time.