Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

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 4523 to 4554

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 == false)
        {
        
copy($path$tmpfile);
        }
    else
        {
        
$tmpfile $copy_hook;
        }

    return 
$tmpfile;
    }

This article was last updated 4th December 2024 09:05 Europe/London time based on the source file dated 28th November 2024 12:10 Europe/London time.