PHP code example of phillip-elm / temp-workspaces

1. Go to this page and download the library: Download phillip-elm/temp-workspaces library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phillip-elm / temp-workspaces example snippets




use PhillipElm\TempWorkspaces\TempDirectoryWorkspace;

function example()
{
  // This creates a workspace and returns it.
  $workspace = TempDirectoryWorkspace::create();

  // This will make a new directory within your workspace.
  $workspace->mkdir('example/test', 0777, true);

  // This will return the full path of the given sub-path relative to the workspace root.
  $path = $workspace->path('example/test/test.txt');

  $workspace->putContents('example/test/test.txt', 'This is a test');

  echo $workspace->getContents('example/test/test.txt');

  // When called without an argument, path() returns the root of the workspace without a trailing slash.
  echo $workspace->path();

  // Once $workspace is destructed, the temporary directory and its contents will be purged.
}