07.09
In a lot of sites you’ll do these days, there’ll be XML driven content and clients who want control over their content. Now somewhere along the line, some silly bugger let the cat out of the bag and told a client that it is possible to write sites that read content directly from the local filestructure in order to build the site content.
“Right”, said the client, and ran off to tell all of his mates that they no longer needed to pay developers every time they needed some of their site’s content updating.
And developers everywhere wept..
Well.. only to a certain degree.. It’s all money at the end of the day, but damn if it’s not boring – and sometimes annoying – as hell to have a client on the end of the phone, hassling you on a sunny Sunday afternoon to get his files cropped and uploaded, when all you want to do is enjoy your bloody weekend and sit in your paddling pool, sipping delicately at your local offie’s finest(cheapest) brew. (pinkie raised and everything
)
Well, in flash dev, we come across things like Download lists, Photo Collections and the suchlike and to enable the client to have maximum control over their photos/documents/videos/etc, we can either write a CMS of some description or just tell them to bung their files in a certain directory on the server.
This script is designed to take a folder name (hard coded to prevent security issues) and scan through it and any subfolders, documenting any files it finds there. As I was writing this, I realised the need for restrictions on what files to show, in case the folder structure contained any files we don’t want available to public viewing – and furthermore, any folders to exclude totally from the outputted XML file.
Example:
Code:
Would happen to have this code in .asp or ASP.Net? Or at least offer a few pointers on how to convert the script? Thanks a lot.
Oh yes, please, give us the script code in ASP/ASP.NET too…
Only just starting to learn .NET, so i may well write a version of this as a learning exercise.
Hi and thanks for this great code .
I would like to now how to delete a node in your code please many thanks
jimie
hi, i am using the xml parse file that is distributed with a file uploader in flash. the thing is that the xml parse file doesnt work when reading folders with special caraters, i mean in UTF8 . is there anything i could do to solve this problem?
regadrs.
Hi,
I just want to pass the username to the swf file and depending on the user name , have to change the basedir in the xmlFileStructure.php to different name..
Any idea on this is much appreciated
Thanks ,
kalai
You can pass values to a swf file using flashvars (described here: http://www.tripleaxis.com/blog/?p=80) and you can then pass that value to the php script using XML.load and putting the username value on the end of the php script url.
Pick it up in the PHP using $_GET[ "username" ] and then you can use it to decide which base folder to use.
Hi,
is there a way to sort the files may be either in alphabetical order or date created
Hi Kalai – You could organise the filenames by storing each folder’s files in an array and then using the sort function to order them alphabetically before writing out the xml.
To order by date created would be more complicated, but again it would involve storing the filenames/creation dates in an array and then sorting them later.
hi,
is there an easy way to return only folders and no files
Hey there, Sana.. you can just change the line that says:
if( $item == “.” || $item == “..” ) continue;
to skip over any files and just concentrate on folders:
if( $item == “.” || $item == “..” || !is_dir($item) ) continue;
-k
Hello, thank you for the code! How can I order folders in alphabetical order. It seems like they are ordered by date created. Thank you!
I am using a multiple file uploader though. Thanks
Is there any way to parse this information into Flash?
Yep. Just use an the XML object to load the data into flash.
e.g.
filedata = new XML();
filedata.load( “XMLFileStructure.php” );
Could you elaborate just a bit; this is all new to me.
Sorry and thank you.
I got it. I was just trying to parse filedata.load(“avatarLister.php”); instead of filedata.load(“http://localhost/xml writer/avatarLister.php”);
Glad you got it sorted
theres one little flaw in your script.. filenames with & in them will give an error
true – filenames with ampersands in them will break the script – just URLEncode the filenames before you output them