diff options
author | jiteshjha | 2016-06-30 16:06:10 +0530 |
---|---|---|
committer | jiteshjha | 2016-06-30 16:06:10 +0530 |
commit | 84195355015154f1dd63a0e3cd612e935075628b (patch) | |
tree | 1d435a2b39e2a3a3ad9ca374bcbfae023533bd01 /filenames.php | |
parent | 981429df495c0b30b4a0a3cfc4cdaf3d096b834b (diff) | |
download | xcos-on-web-84195355015154f1dd63a0e3cd612e935075628b.tar.gz xcos-on-web-84195355015154f1dd63a0e3cd612e935075628b.tar.bz2 xcos-on-web-84195355015154f1dd63a0e3cd612e935075628b.zip |
Code refactoring
Diffstat (limited to 'filenames.php')
-rw-r--r-- | filenames.php | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/filenames.php b/filenames.php new file mode 100644 index 0000000..3355ac3 --- /dev/null +++ b/filenames.php @@ -0,0 +1,27 @@ +<?php + +/* + * @jiteshjha + * getFilename returns the names of all the files in a given folder + */ + +// Store the filenames +$filenameArray = []; + +// Get the folder to be operated +$url = $_POST['url']; + +// Open the file directory and get the filehandle +// Reference: http://php.net/manual/en/function.opendir.php +$handle = opendir(dirname(realpath(__FILE__)).$url); + +// For each file in the folder, push the filename to filenameArray +while($file = readdir($handle)){ + if($file !== '.' && $file !== '..'){ + array_push($filenameArray, "$url$file"); + } +} + +// Return the file name array in JSON format +echo json_encode($filenameArray); +?> |