3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Use of undefined constant pickfile - assumed 'pickfile' in /in/oHhhL on line 49 <form name="pickFile" method="POST"> Warning: opendir(.): failed to open dir: Permission denied in /in/oHhhL on line 18 <select name="folder" onchange="changeFolder(this.value);"> </select><br><br> Notice: Use of undefined constant folder - assumed 'folder' in /in/oHhhL on line 70 Notice: Undefined index: folder in /in/oHhhL on line 70 Notice: Use of undefined constant name - assumed 'name' in /in/oHhhL on line 70 Notice: Undefined offset: 0 in /in/oHhhL on line 70 Warning: opendir(./): failed to open dir: Permission denied in /in/oHhhL on line 18 <select name="file"> </select><br><br><button type="submit" name="pickfile">Submit</button>
Output for hhvm-3.10.0 - 3.12.0
Notice: Use of undefined constant pickfile - assumed 'pickfile' in /in/oHhhL on line 49 <form name="pickFile" method="POST"> Warning: Permission denied in /in/oHhhL on line 18 <select name="folder" onchange="changeFolder(this.value);"> </select><br><br> Notice: Use of undefined constant folder - assumed 'folder' in /in/oHhhL on line 70 Notice: Undefined index: folder in /in/oHhhL on line 70 Notice: Use of undefined constant name - assumed 'name' in /in/oHhhL on line 70 Notice: Undefined index: 0 in /in/oHhhL on line 70 Warning: Permission denied in /in/oHhhL on line 18 <select name="file"> </select><br><br><button type="submit" name="pickfile">Submit</button>
Output for 4.3.2 - 5.2.17
Notice: Use of undefined constant pickfile - assumed 'pickfile' in /in/oHhhL on line 49 <form name="pickFile" method="POST"> Warning: opendir(.): failed to open dir: Permission denied in /in/oHhhL on line 18 <select name="folder" onchange="changeFolder(this.value);"> </select><br><br> Notice: Use of undefined constant folder - assumed 'folder' in /in/oHhhL on line 70 Notice: Undefined index: folder in /in/oHhhL on line 70 Notice: Use of undefined constant name - assumed 'name' in /in/oHhhL on line 70 Notice: Undefined offset: 0 in /in/oHhhL on line 70 Warning: opendir(./): failed to open dir: Permission denied in /in/oHhhL on line 18 <select name="file"> </select><br><br><button type="submit" name="pickfile">Submit</button>
Output for 4.3.0 - 4.3.1
Notice: Use of undefined constant pickfile - assumed 'pickfile' in /in/oHhhL on line 49 <form name="pickFile" method="POST"> Warning: opendir(.) [http://www.php.net/function.opendir]: failed to open dir: Permission denied in /in/oHhhL on line 18 <select name="folder" onchange="changeFolder(this.value);"> </select><br><br> Notice: Use of undefined constant folder - assumed 'folder' in /in/oHhhL on line 70 Notice: Undefined index: folder in /in/oHhhL on line 70 Notice: Use of undefined constant name - assumed 'name' in /in/oHhhL on line 70 Notice: Undefined offset: 0 in /in/oHhhL on line 70 Warning: opendir(./) [http://www.php.net/function.opendir]: failed to open dir: Permission denied in /in/oHhhL on line 18 <select name="file"> </select><br><br><button type="submit" name="pickfile">Submit</button>