Skip to content

Instantly share code, notes, and snippets.

@inri13666
Last active February 19, 2019 21:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inri13666/4f7484af32ac7eba81b0d1bf8a5a5111 to your computer and use it in GitHub Desktop.
Save inri13666/4f7484af32ac7eba81b0d1bf8a5a5111 to your computer and use it in GitHub Desktop.
PHP File-system challenge
mkdir -p /tmp/test/realcachefolder/gretta
ln -s /tmp/test/realcachefolder /tmp/test/symlinkcachefolder
cd /tmp/test/symlinkcachefolder
php -r "var_dump(realpath('/tmp/test/symlinkcachefolder'));"
php -r "var_dump(__DIR__);"

create index.php with following content at /tmp/test/symlinkcachefolder

<?php 
var_dump([ 
	'realpath(__DIR__)' => realpath(__DIR__),
	'realpath("/tmp/test/symlinkcachefolder/gretta")' => realpath("/tmp/test/symlinkcachefolder/gretta"),
	'dirname(__DIR__)' => dirname(__DIR__),
	'dirname(__DIR__ . "/gretta")' => dirname(__DIR__ . "/gretta"),
]);

and execute it

php index.php
php -v

output

root@akuma01:/# mkdir -p /tmp/test/realcachefolder/gretta
root@akuma01:/# ln -s /tmp/test/realcachefolder /tmp/test/symlinkcachefolder
root@akuma01:/# cd /tmp/test/symlinkcachefolder
root@akuma01:/tmp/test/symlinkcachefolder# php -r "var_dump(realpath('/tmp/test/symlinkcachefolder'));"
string(25) "/tmp/test/realcachefolder"
root@akuma01:/tmp/test/symlinkcachefolder# php -r "var_dump(__DIR__);"
string(25) "/tmp/test/realcachefolder"
root@akuma01:/tmp/test/symlinkcachefolder# mcedit index.php

root@akuma01:/tmp/test/symlinkcachefolder# php index.php
array(4) {
  ["realpath(__DIR__)"]=>
  string(25) "/tmp/test/realcachefolder"
  ["realpath("/tmp/test/symlinkcachefolder/gretta")"]=>
  string(32) "/tmp/test/realcachefolder/gretta"
  ["dirname(__DIR__)"]=>
  string(9) "/tmp/test"
  ["dirname(__DIR__ . "/gretta")"]=>
  string(25) "/tmp/test/realcachefolder"
}
root@akuma01:/tmp/test/symlinkcachefolder# php -v
PHP 7.0.16-4+deb.sury.org~precise+1 (cli) (built: Mar  2 2017 13:13:10) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.16-4+deb.sury.org~precise+1, Copyright (c) 1999-2017, by Zend Technologies
root@akuma01:/tmp/test/symlinkcachefolder#
mkdir D:\test\realcachefolder\gretta
mklink /J D:\test\symlinkedcachefolder D:\test\realcachefolder
cd D:\test
dir
cd symlinkedcachefolder
dir
php -r "var_dump(realpath('D:/test/symlinkedcachefolder'));"
php -r "var_dump(__DIR__);"

create index.php with following content at D:\test\symlinkedcachefolder

<?php 
var_dump([ 
	'realpath(__DIR__)' => realpath(__DIR__),
	'realpath("D:\test\symlinkedcachefolder\gretta")' => realpath("D:\test\symlinkedcachefolder\gretta"),
	'dirname(__DIR__)' => dirname(__DIR__),
	'dirname(__DIR__ . "\gretta")' => dirname(__DIR__ . "\gretta"),
]);

and execute it

php index.php
php -v

output

D:\>mkdir D:\test\realcachefolder\gretta

D:\>mklink /J D:\test\symlinkedcachefolder D:\test\realcachefolder
Junction created for D:\test\symlinkedcachefolder <<===>> D:\test\realcachefolder

D:\>cd D:\test

D:\test>dir
 Volume in drive D is dev
 Volume Serial Number is ECD3-824B

 Directory of D:\test

02/19/2019  02:22 PM    <DIR>          .
02/19/2019  02:22 PM    <DIR>          ..
02/19/2019  02:22 PM    <DIR>          realcachefolder
02/19/2019  02:22 PM    <JUNCTION>     symlinkedcachefolder [D:\test\realcachefolder]
               0 File(s)              0 bytes
               4 Dir(s)  34,949,652,480 bytes free

D:\test>cd symlinkedcachefolder

D:\test\symlinkedcachefolder>dir
 Volume in drive D is dev
 Volume Serial Number is ECD3-824B

 Directory of D:\test\symlinkedcachefolder

02/19/2019  02:22 PM    <DIR>          .
02/19/2019  02:22 PM    <DIR>          ..
02/19/2019  02:22 PM    <DIR>          gretta
               0 File(s)              0 bytes
               3 Dir(s)  34,949,652,480 bytes free

D:\test\symlinkedcachefolder>php -r "var_dump(realpath('D:/test/symlinkedcachefolder'));"
string(23) "D:\test\realcachefolder"

D:\test\symlinkedcachefolder>php -r "var_dump(__DIR__);"
string(28) "D:\test\symlinkedcachefolder"

D:\test\symlinkedcachefolder>php index.php
array(4) {
  ["realpath(__DIR__)"]=>
  string(23) "D:\test\realcachefolder"
  ["realpath("D:\test\symlinkedcachefolder\gretta")"]=>
  bool(false)
  ["dirname(__DIR__)"]=>
  string(7) "D:\test"
  ["dirname(__DIR__ . "\gretta")"]=>
  string(23) "D:\test\realcachefolder"
}

D:\test\symlinkedcachefolder>php -v
PHP 7.1.26 (cli) (built: Jan  9 2019 21:51:32) ( ZTS MSVC14 (Visual C++ 2015) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment