note 119130 deleted from features.commandline.webserver by peehaa

From: Date: Wed, 19 Oct 2016 09:34:34 +0000
Subject: note 119130 deleted from features.commandline.webserver by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-206923@lists.php.net to get a copy of this message
Note Submitter: yuanoook at gmail dot com ---- This is my local php server <?php $request_uri = '.'.urldecode($_SERVER['REQUEST_URI']); if( is_dir($request_uri) ){ // server use the relative directory $dirname = preg_replace('/\/{2}/', '/', $request_uri.'/'); $files_arr = array_filter(scandir($dirname), function($file_name){ return false == (bool)preg_match('/^\.+/', $file_name); }); // browser use the absolute path_name which bases on the server root directory $browser_path = preg_replace('/^\./', '', $dirname); printf('<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"> </head> <body> %s </body> </html>', implode( preg_replace('/^(.*)$/', '<a href="'.$browser_path.'${1}">${1}</a>', $files_arr), '<br/>' ) ); }else{ header('Content-Type: '.mime_content_type($request_uri)); echo file_get_contents($request_uri); }

« previous php.notes (#206923) next »