jackpf obviously understood you, but that's a new expression for me (being an old, brash American), and I'd seriously enjoy knowing what that means. I tried Wikipedia and I Googled it and found lots of instances, but no definition.MiniMonty wrote:LOL - don't take the mick - I'm really new to this !
Newb advice
Moderator: General Moderators
Re: Newb advice
Re: Newb advice
Jack - it works a treat, cheers.
Next step...
So I now have a directory with 1.jpg, 2.jpg, 3.jpg etc.,
The front end of this monster will eventually be built in Flash which will want
to import an array which looks like this:
"photos = ["portraits/1.jpg", "portraits/2.jpg", "portraits/3.jpg", "portraits/4.jpg", "portraits/5.jpg"];"
(unless anyone has a better idea / solution of course)
Any advice / pointers / links on how to take the contents of my directory and build the list into an array ?
Best wishes
Monty
Next step...
So I now have a directory with 1.jpg, 2.jpg, 3.jpg etc.,
The front end of this monster will eventually be built in Flash which will want
to import an array which looks like this:
"photos = ["portraits/1.jpg", "portraits/2.jpg", "portraits/3.jpg", "portraits/4.jpg", "portraits/5.jpg"];"
(unless anyone has a better idea / solution of course)
Any advice / pointers / links on how to take the contents of my directory and build the list into an array ?
Best wishes
Monty
Re: Newb advice
You already HAVE access to that array that's returned from glob()...MiniMonty wrote:Jack - it works a treat, cheers.
Next step...
So I now have a directory with 1.jpg, 2.jpg, 3.jpg etc.,
The front end of this monster will eventually be built in Flash which will want
to import an array which looks like this:
"photos = ["portraits/1.jpg", "portraits/2.jpg", "portraits/3.jpg", "portraits/4.jpg", "portraits/5.jpg"];"
(unless anyone has a better idea / solution of course)
Any advice / pointers / links on how to take the contents of my directory and build the list into an array ?
Best wishes
Monty
php > print_r(glob("/home/mike/Pictures/*"));
Array
(
[0] => /home/mike/Pictures/car1.jpg
[1] => /home/mike/Pictures/car2.jpg
[2] => /home/mike/Pictures/car3.jpg
[3] => /home/mike/Pictures/car4.jpg
[4] => /home/mike/Pictures/car5.jpg
[5] => /home/mike/Pictures/car6.jpg
[6] => /home/mike/Pictures/car7.jpg
[7] => /home/mike/Pictures/car8.jpg
[8] => /home/mike/Pictures/car9.jpg
)
php >
Re: Newb advice
You have a list of files from glob(), like I posted before.
http://www.peevish.co.uk/slang/t.htm#take_the_mickey
I suggest you brush up on your british slang
EDIT
Mirge, just saw your post - yeah, basically the same idea.
Haha, you americans....califdon wrote:jackpf obviously understood you, but that's a new expression for me (being an old, brash American), and I'd seriously enjoy knowing what that means. I tried Wikipedia and I Googled it and found lots of instances, but no definition.MiniMonty wrote:LOL - don't take the mick - I'm really new to this !
http://www.peevish.co.uk/slang/t.htm#take_the_mickey
I suggest you brush up on your british slang
EDIT
Mirge, just saw your post - yeah, basically the same idea.
Re: Newb advice
Mirge wrote:You already HAVE access to that array that's returned from glob()...MiniMonty wrote:Jack - it works a treat, cheers.
Next step...
So I now have a directory with 1.jpg, 2.jpg, 3.jpg etc.,
The front end of this monster will eventually be built in Flash which will want
to import an array which looks like this:
"photos = ["portraits/1.jpg", "portraits/2.jpg", "portraits/3.jpg", "portraits/4.jpg", "portraits/5.jpg"];"
(unless anyone has a better idea / solution of course)
Any advice / pointers / links on how to take the contents of my directory and build the list into an array ?
Best wishes
Monty
php > print_r(glob("/home/mike/Pictures/*"));
Array
(
[0] => /home/mike/Pictures/car1.jpg
[1] => /home/mike/Pictures/car2.jpg
[2] => /home/mike/Pictures/car3.jpg
[3] => /home/mike/Pictures/car4.jpg
[4] => /home/mike/Pictures/car5.jpg
[5] => /home/mike/Pictures/car6.jpg
[6] => /home/mike/Pictures/car7.jpg
[7] => /home/mike/Pictures/car8.jpg
[8] => /home/mike/Pictures/car9.jpg
)
php >
Sweet as a nut. ON a step curve here but learning a lot today. Thanks.
Off to do some reading now to learn how to strip out all the [0] => bits and bobs and format the data for easy-reading in Flash.
Any pointers to good tutorial sites (I can't let you very helpful people write the whole thing for me) !
EDIT: One last question - can I name the array to identify it when it's imported to Flash ?
Or am I wiser to print it into a separate .txt file and import from there ?
Any opinions ?
Best wishes
Monty
Re: Newb advice
I don't know how flash works, but you don't need to use print_r() to display an array. I think you want implode().
Re: Newb advice
MiniMonty wrote:Mirge wrote:You already HAVE access to that array that's returned from glob()...MiniMonty wrote:Jack - it works a treat, cheers.
Next step...
So I now have a directory with 1.jpg, 2.jpg, 3.jpg etc.,
The front end of this monster will eventually be built in Flash which will want
to import an array which looks like this:
"photos = ["portraits/1.jpg", "portraits/2.jpg", "portraits/3.jpg", "portraits/4.jpg", "portraits/5.jpg"];"
(unless anyone has a better idea / solution of course)
Any advice / pointers / links on how to take the contents of my directory and build the list into an array ?
Best wishes
Monty
php > print_r(glob("/home/mike/Pictures/*"));
Array
(
[0] => /home/mike/Pictures/car1.jpg
[1] => /home/mike/Pictures/car2.jpg
[2] => /home/mike/Pictures/car3.jpg
[3] => /home/mike/Pictures/car4.jpg
[4] => /home/mike/Pictures/car5.jpg
[5] => /home/mike/Pictures/car6.jpg
[6] => /home/mike/Pictures/car7.jpg
[7] => /home/mike/Pictures/car8.jpg
[8] => /home/mike/Pictures/car9.jpg
)
php >
Sweet as a nut. ON a step curve here but learning a lot today. Thanks.
Off to do some reading now to learn how to strip out all the [0] => bits and bobs and format the data for easy-reading in Flash.
Any pointers to good tutorial sites (I can't let you very helpful people write the whole thing for me) !
EDIT: One last question - can I name the array to identify it when it's imported to Flash ?
Or am I wiser to print it into a separate .txt file and import from there ?
Any opinions ?
Best wishes
Monty
I was only using print_r() to show that it was an array and to display its contents. You can do whatever you want with the PHP array. If you are wanting a JSON-type format, there are plenty of ways to accomplish that.
EDIT:
If you're just wanting it in that simple of a format, do something like:
Code: Select all
<?php
$filesArray = glob("/home/mike/Pictures/*");
$filesString = '[';
$count = 0;
foreach($filesArray as $filename) {
if($count > 0) {
$filesString .= ", ";
}
$filesString .= "\"$filename\"";
$count++;
}
$filesString .= ']';
print "$filesString\n";
?>
["/home/mike/Pictures/car1.jpg", "/home/mike/Pictures/car2.jpg", "/home/mike/Pictures/car3.jpg", "/home/mike/Pictures/car4.jpg", "/home/mike/Pictures/car5.jpg", "/home/mike/Pictures/car6.jpg", "/home/mike/Pictures/car7.jpg", "/home/mike/Pictures/car8.jpg", "/home/mike/Pictures/car9.jpg"]
Not the most elegant code, but it works.
Re: Newb advice
That output is exactly what I'm after - only trouble is that I copied your code, ran it on the server and got
"Unexpected T_Variable on line 3"
Any ideas?
"Unexpected T_Variable on line 3"
Any ideas?
Last edited by MiniMonty on Fri Sep 04, 2009 4:14 pm, edited 1 time in total.
Re: Newb advice
That output is exactly what I'm after - only trouble is that I copied your code, ran it on the server and gotMiniMonty wrote:I was only using print_r() to show that it was an array and to display its contents. You can do whatever you want with the PHP array. If you are wanting a JSON-type format, there are plenty of ways to accomplish that.
EDIT:
If you're just wanting it in that simple of a format, do something like:
Which outputs (meaning $fileString contains):Code: Select all
<?php $filesArray = glob("/home/mike/Pictures/*"); $filesString = '['; $count = 0; foreach($filesArray as $filename) { if($count > 0) { $filesString .= ", "; } $filesString .= "\"$filename\""; $count++; } $filesString .= ']'; print "$filesString\n"; ?>
["/home/mike/Pictures/car1.jpg", "/home/mike/Pictures/car2.jpg", "/home/mike/Pictures/car3.jpg", "/home/mike/Pictures/car4.jpg", "/home/mike/Pictures/car5.jpg", "/home/mike/Pictures/car6.jpg", "/home/mike/Pictures/car7.jpg", "/home/mike/Pictures/car8.jpg", "/home/mike/Pictures/car9.jpg"]
Not the most elegant code, but it works.
"Unexpected T_Variable on line 3"
Any ideas?[/quote]
Paste your code, so we can see what lines 1-10 are at least.
Re: Newb advice
Same as yours...
Code: Select all
<?php
$filesArray = glob("/path/to/directory/*");
$filesString = '[';
$count = 0;
foreach($filesArray as $filename) {
if($count > 0) {
$filesString .= ", ";
}
$filesString .= "\"$filename\"";
$count++;
}
$filesString .= ']';
print "$filesString\n";
?>
Re: Newb advice
Then it's somewhere else in your code, because I copy/pasted *that*... changed the path to /home/mike/Pictures/*, and ran it... and it gave the expected output:MiniMonty wrote:Same as yours...
Code: Select all
<?php $filesArray = glob("/path/to/directory/*"); $filesString = '['; $count = 0; foreach($filesArray as $filename) { if($count > 0) { $filesString .= ", "; } $filesString .= "\"$filename\""; $count++; } $filesString .= ']'; print "$filesString\n"; ?>
["/home/mike/Pictures/car1.jpg", "/home/mike/Pictures/car2.jpg", "/home/mike/Pictures/car3.jpg", "/home/mike/Pictures/car4.jpg", "/home/mike/Pictures/car5.jpg", "/home/mike/Pictures/car6.jpg", "/home/mike/Pictures/car7.jpg", "/home/mike/Pictures/car8.jpg", "/home/mike/Pictures/car9.jpg"]
Re: Newb advice
That's really frustrating because I copy/pasted it, ran it as a stand-alone file and I get
"Parse error: syntax error, unexpected T_VARIABLE in /blah/blah/blah/nicearray.php on line 3"
Could it be something to do with the server (it's Linux) or the version of php ?
If the code is identical (and it is save for the path) it must be some other factor.
Any ideas ? Any tests I can do ?
I'm really grateful to you lot for all your help by the way - I thought this would take a week and
so far it's taken a day and I've got a lot further than I'd hoped.
"Parse error: syntax error, unexpected T_VARIABLE in /blah/blah/blah/nicearray.php on line 3"
Could it be something to do with the server (it's Linux) or the version of php ?
If the code is identical (and it is save for the path) it must be some other factor.
Any ideas ? Any tests I can do ?
I'm really grateful to you lot for all your help by the way - I thought this would take a week and
so far it's taken a day and I've got a lot further than I'd hoped.
Re: Newb advice
Btw, you could do this in like one line if you use implode().
Re: Newb advice
I thought about that first, using implode/join, but couldn't find out a way to actually wrap the filenames with quotes, and have an ending comma... using only implode/join.jackpf wrote:Btw, you could do this in like one line if you use implode().
Re: Newb advice
Forgive the pun but... care to expand on that ?jackpf wrote:Btw, you could do this in like one line if you use implode().