+

PHP Tmpfile () function

Syntax:
tmpfile()
Return Value:
Returns the file descriptor for the new file in on success or FALSE on error.Errors and Exceptions:
  • The temporary file is automatically deleted when it is closed with fclose(), or when the script ends.
  • The tmpfile() function returns Boolean False, but it often happens that it returns a non-boolean value that evaluates to False.
  • Examples:
    Input: $temp_pointer = tmpfile(); fwrite ($temp_pointer, `temporary data`); fclose (temp_pointer); Output: 1 Input: $temp_pointer = tmpfile(); fwrite ($temp_pointer, "GeeksforGeeks"); echo fread ($temp_pointer, 2048); fclose ($temp); Output: Geeksforengineer 
    The programs below illustrate the tmpfile() function.Program 1
    // PHP program to illustrate the tmpfile() function $temp_pointer = tmpfile();  
    // Write to temporary file fwrite ( $temp_pointer , ` temporary data` );  
    // This deletes the file
    fclose (temp_pointer);  
    ?>
    Output:
    1 
    Program 2 // PHP program to illustrate the tmpfile() function $temp_pointer = tmpfile();  
    // Write to temporary file fwrite ( $temp_pointer , " GeeksforGeeks " );  
    // Read 2k from file echo fread ( $temp_pointer , 2048);  
    // This deletes the file fclose ( $temp_pointer );  
    ?>
    Output:
    GeeksforGeeks 
    Link:
    http: / /php.net/manual/en/function.tmpfile.php
    Get Solution for free from DataCamp guru