PHP Help
- Started
- Last post
- 10 Responses
- rabbit0
you need to create an empty array, push each item into the array then sort it and output it:
<?php
function getAllImagesInDirectory($path) {
if ($handle = opendir($path)) {
$images = array();
while (false !== ($file = readdir($handle))) {
if($file !== "." && $file !== "..") {
array_push($images, $path.'\\'.$file);
}}
closedir($handle);asort($images);
foreach ($images as $key => $val) {
echo "$key = $val\n";
}}
}
?>
- ESKEMA0
Also, is there a way to get the function to get the image list ordered alphabetically? Right now it just throws everything randomly...
- ESKEMA0
Ok, I'm going to try and explain it better.
I'm trying to implement Supersized in a Concrete5 Theme, with the ability to give a different target image folder for each project.
But I think I found the solution, I'll have to shell out some bucks for an addon (to inject code from the edit mode) and try it out. I'll post updates after...
Thank you for the help
- rabbit0
sorry, with the above files, to solve the problem you have i think you want to move:
$output = getAllImagesInDirectory("C:\User...
from fileWithFunction.php to output.php
voila!
- rabbit0
http://pastebin.com/YkDMykAw
http://pastebin.com/S0bvLPKSyour two files
- also be aware this grabs all file types in specified directory, not just imagesrabbit
- sine0
i'm glad i'm not doing this shit anymore
- rabbit0
if i understand correctly, you need two files:
fileWithFunction.php
<?phpfunction getAllImagesInDirectory($path) {
if ($handle = opendir($path)) {
$images = "[";
while (false !== ($file = readdir($handle))) {
if($file !== "." && $file !== "..") {
$images .= "{image : '$path$file', title : '', url : ''},";
}
}
closedir($handle);
return substr($images,0,strlen($images)-1) . "]";
}}
$output = getAllImagesInDirectory("C:\Users\jbstrand\Downloads");
?>
output.php:
<?php
require("fileWithFunction.php");
echo $output;
?>
- section_0140
uan is right, assigning it to a variable would have no effect on whether or not it is echoed.
I think the problem lies in the way you are echo'ing out $path$file. Generally, you should have a dot between them like this $path . $file
Finally, I think your quotation marks are off. Try this:
$images .= "{image : " . $path . $file . ", title : '', url : ''},";
- apparently you can echo string vars inside double quotes, but I wouldn't as it's not common practicesection_014
- ESKEMA0
It works if I put the two lines together,
but what I want is have the first line in one document and the second line in another, but yeah, the echo comes empty and I would like to sort this out. I'm no PHP expert, so I'm basically scratching my head here..
- uan0
$workslides is most probably empty when you you echo it...
...some path issue maybe.
- ESKEMA
I have this function:
that is echoed like this:
echo getAllImagesInDirectory("works/j...
I want to change the echo to this:
$workslides = getAllImagesInDirectory("works/j...
echo $workslides;If I put them together in the same line they work, but I want the var definition being written in another document (so that I can change the folder path) and that isn't working..
Any help appreciated.