3v4l.org

run code in 300+ PHP versions simultaneously
<?php $parent_directory = '.'; $file_types = 'jpg,png,gif,tif'; //===================================================// // FUNCTION: directoryToArray // // // // Parameters: // // - $root: The directory to process // // - $to_return: f=files, d=directories, b=both // // - $file_types: the extensions of file types to // // to return if files selected // //===================================================// function directoryToArray($root, $to_return='b', $file_types=false) { $array_items = array(); if ($file_types) { $file_types=explode(',',$file_types); } if ($handle = opendir($root)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $add_item = false; $type = (is_dir($root. "/" . $file))?'d':'f'; $name = preg_replace("/\/\//si", "/", $file); if ($type=='d' && ($to_return=='b' || $to_return=='d') ) { $add_item = true; } if ($type=='f' && ($to_return=='b' || $to_return=='f') ) { $ext = end(explode('.',$name)); if ( !$file_types || in_array($ext, $file_types) ) { $add_item = true; } } if ($add_item) { $array_items[] = array ( 'name'=>$name, 'type'=>$type, 'root'=>$root); } } } // End While closedir($handle); } // End If return $array_items; } if (isset($_POST[pickfile])) { // User has selected a file take whatever action you want based // upon the values for folder and file } else { echo "<form name=\"pickFile\" method=\"POST\">\n"; $directoryList = directoryToArray($parent_directory,'d'); echo "<select name=\"folder\" onchange=\"changeFolder(this.value);\">\n"; foreach ($directoryList as $folder) { $selected = ($_POST[folder]==$folder[name])? 'selected' : ''; echo "<option value=\"$folder[name]\" $selected>$folder[name]</option>\n"; } echo '</select><br><br>'; $working_folder = ($_POST[folder]) ? $_POST[folder] : $directoryList[0][name]; $fileList = directoryToArray($parent_directory.'/'.$working_folder,'f',$file_types); echo "<select name=\"file\">\n"; foreach ($fileList as $file) { echo "<option value=\"$file[name]\">$file[name]</option>\n"; } echo '</select><br><br>'; echo "<button type=\"submit\" name=\"pickfile\">Submit</button>\n"; } ?>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Fatal error: Uncaught Error: Undefined constant "pickfile" in /in/oHhhL:49 Stack trace: #0 {main} thrown in /in/oHhhL on line 49
Process exited with code 255.
Output for 7.4.33
Warning: Use of undefined constant pickfile - assumed 'pickfile' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 49 <form name="pickFile" method="POST"> <select name="folder" onchange="changeFolder(this.value);"> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="var" >var</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="dev" >dev</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="run" >run</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="etc" >etc</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="tmp" >tmp</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="sys" >sys</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="proc" >proc</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="usr" >usr</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="bin" >bin</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="boot" >boot</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="home" >home</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="lib" >lib</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="lib64" >lib64</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="mnt" >mnt</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="opt" >opt</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="root" >root</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="sbin" >sbin</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="srv" >srv</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Notice: Undefined index: folder in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="in" >in</option> </select><br><br> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 70 Notice: Undefined index: folder in /in/oHhhL on line 70 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 70 Notice: Only variables should be passed by reference in /in/oHhhL on line 31 <select name="file"> </select><br><br><button type="submit" name="pickfile">Submit</button>
Output for 7.4.26 - 7.4.32
Warning: Use of undefined constant pickfile - assumed 'pickfile' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 49 <form name="pickFile" method="POST"> Warning: opendir(): open_basedir restriction in effect. File(.) is not within the allowed path(s): (/tmp:/in:/etc) in /in/oHhhL on line 18 Warning: opendir(.): failed to open dir: Operation not permitted in /in/oHhhL on line 18 <select name="folder" onchange="changeFolder(this.value);"> </select><br><br> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 70 Notice: Undefined index: folder in /in/oHhhL on line 70 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 70 Notice: Undefined offset: 0 in /in/oHhhL on line 70 Notice: Trying to access array offset on value of type null in /in/oHhhL on line 70 Warning: opendir(): open_basedir restriction in effect. File(./) is not within the allowed path(s): (/tmp:/in:/etc) in /in/oHhhL on line 18 Warning: opendir(./): failed to open dir: Operation not permitted in /in/oHhhL on line 18 <select name="file"> </select><br><br><button type="submit" name="pickfile">Submit</button>
Output for 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.25
Warning: Use of undefined constant pickfile - assumed 'pickfile' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 49 <form name="pickFile" method="POST"> <select name="folder" onchange="changeFolder(this.value);"> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="var" >var</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="dev" >dev</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="run" >run</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="etc" >etc</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="tmp" >tmp</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="sys" >sys</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="proc" >proc</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="usr" >usr</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="bin" >bin</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="boot" >boot</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="home" >home</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="lib" >lib</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="lib64" >lib64</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="mnt" >mnt</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="opt" >opt</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="root" >root</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="sbin" >sbin</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="srv" >srv</option> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 65 <option value="in" >in</option> </select><br><br> Warning: Use of undefined constant folder - assumed 'folder' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 70 Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /in/oHhhL on line 70 <select name="file"> </select><br><br><button type="submit" name="pickfile">Submit</button>
Output for 5.2.3 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33
<form name="pickFile" method="POST"> <select name="folder" onchange="changeFolder(this.value);"> <option value="var" >var</option> <option value="dev" >dev</option> <option value="run" >run</option> <option value="etc" >etc</option> <option value="tmp" >tmp</option> <option value="sys" >sys</option> <option value="proc" >proc</option> <option value="usr" >usr</option> <option value="bin" >bin</option> <option value="boot" >boot</option> <option value="home" >home</option> <option value="lib" >lib</option> <option value="lib64" >lib64</option> <option value="mnt" >mnt</option> <option value="opt" >opt</option> <option value="root" >root</option> <option value="sbin" >sbin</option> <option value="srv" >srv</option> <option value="in" >in</option> </select><br><br><select name="file"> </select><br><br><button type="submit" name="pickfile">Submit</button>
Output for 4.4.3 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.2
<form name="pickFile" method="POST"> <br /> <b>Warning</b>: opendir(.) [<a href='function.opendir'>function.opendir</a>]: failed to open dir: Permission denied in <b>/in/oHhhL</b> on line <b>18</b><br /> <select name="folder" onchange="changeFolder(this.value);"> </select><br><br><br /> <b>Warning</b>: opendir(./) [<a href='function.opendir'>function.opendir</a>]: failed to open dir: Permission denied in <b>/in/oHhhL</b> on line <b>18</b><br /> <select name="file"> </select><br><br><button type="submit" name="pickfile">Submit</button>
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.2
<form name="pickFile" method="POST"> <br /> <b>Warning</b>: opendir(.): failed to open dir: Permission denied in <b>/in/oHhhL</b> on line <b>18</b><br /> <select name="folder" onchange="changeFolder(this.value);"> </select><br><br><br /> <b>Warning</b>: opendir(./): failed to open dir: Permission denied in <b>/in/oHhhL</b> on line <b>18</b><br /> <select name="file"> </select><br><br><button type="submit" name="pickfile">Submit</button>
Output for 4.3.0 - 4.3.1
<form name="pickFile" method="POST"> <br /> <b>Warning</b>: opendir(.) [<a href='http://www.php.net/function.opendir'>function.opendir</a>]: failed to open dir: Permission denied in <b>/in/oHhhL</b> on line <b>18</b><br /> <select name="folder" onchange="changeFolder(this.value);"> </select><br><br><br /> <b>Warning</b>: opendir(./) [<a href='http://www.php.net/function.opendir'>function.opendir</a>]: failed to open dir: Permission denied in <b>/in/oHhhL</b> on line <b>18</b><br /> <select name="file"> </select><br><br><button type="submit" name="pickfile">Submit</button>

preferences:
303.18 ms | 402 KiB | 469 Q