|
<?php
/*
* Simple Flash File Browse
* Inputs - this script expects a directory path as input.
* Author: Jeffrey Hill
* Site: www.flash-db.com/remoting/
*/
class filebrowse
{
function filebrowse()
{
$this->methodTable = array(
"getFiles" => array(
"description" => "Returns a list of files in a given directory.",
"access" => "remote",
"arguments" => array ("directory","showAll") // if showAll is yes - then it will list sub directories.
)
);
}
function getFiles($directory,$showAll) {
// Create List of Files
// open up file directory.
if (is_dir($directory)) {
if ($dh = opendir($directory)) {
$i = 0;
while (($file = readdir($dh)) !== false) {
// this determines if you want to show everything in the directory.
// You can also modify this to only show a certain type of file(s).
if ($showAll != 'yes') {
if ($file != "." && $file != "..") {
// returns the file name as an array.
$temp["fileName"][$i] = $file;
// returns the file description - ie directory, file, etc.
$temp["fileType"][$i] = filetype($directory . $file);
$i++;
}
} else {
// returns the file name as an array.
$temp["fileName"][$i] = $file;
// returns the file description - ie directory, file, etc.
$temp["fileType"][$i] = filetype($directory . $file);
$i++;
}
}
closedir($dh);
// return an array of file names and types
return $temp;
} else {
// return an error if the directory could not be opened.
return 'There was an error when trying to open the specified directory ('.$directory.') .';
}
} else {
// adds some error handling if the directory can not be located.
return 'The Directory was not found ('.$directory.'). Please check the directory path.';
}
}
}
?>
|
|
#include "NetServices.as"
#include "NetDebug.as"
myResult = new Object();
myResult.onResult = function(result){
for (var i in result.fileName) {
// Loop through results and add to dataprovider.
dataProvider = { fileName:result.fileName[i]};
// The listbox has an instance name of category.
files.addItem(result.fileName[i],dataProvider);
}
}
myResult.onStatus = function(status){
trace("Error: " + status.description);
}
System.onStatus = myResult.onStatus;
// Create a connection to your gateway.
var conn = NetServices.createGatewayConnection("http:// Path to Gateway.php on your server");
// Specify the service you want to use. There has to be a file called 'filebrowse.php' in your
// services directory.
var myService = conn.getService("filebrowse", myResult);
getFiles_btn.onPress = function() {
var directory = "../../DirectoryToBrowse/";
var showAll = ''; // can be either yes or nothing. If set to yes will show everything, including sub directories.
// Call the service. This takes 2 inputs - the directory you want to browse and a showAll param.
myService.getFiles(directory, showAll);
}
|