/    Sign up×
Community /Pin to ProfileBookmark

Use folder name as option for HTML

Hi.

I have folders that contain images that has to be displayed in a website. I can’t name them in my

[code]<option></option>[/code]

in a static manner because they are dates.

this is the html code:

[code]
<select multiple class=”form-control”>
<option selected disabled>Select an Initialization Date</option>
<option selected value=”archived_date1″></option>
<option value=”archived_date2″></option>
<option value=”archived_date3″></option>
<option value=”archived_date4″></option>
<option value=”archived_date5″></option>
<option value=”archived_date6″></option>
<option value=”archived_date7″></option>
<option value=”archived_date8″></option>
</select>
[/code]

I tried to use the

[code]scandir ()[/code]

but I it only lists the folders in my specified directory.

This was my test with

[code]scandir[/code]

:

[code]
$completepath=(‘../operations/archived_runs/pywrf_output/d01’);
// scan dir
$date=scandir($completepath);

print_r($date);
[/code]

this was the output:

[code]
[]Array ( [0] => . [1] => .. [2] => 20220727_1500 [3] => 20220727_1800 [4] => 20220727_2100 [5] => 20220728_0000 [6] => 20220728_0300 )
[/code]

I was hoping to incorporate this functionality in my php script that displays images.

[code]

ini_set(‘display_errors’, 1);
ini_set(‘display_startup_errors’, 1);
error_reporting(E_ALL);

// GET PARAMETERS
$date_folder = $_GET[‘date_folder’];
$domain = $_GET[‘domain’];
$path = $_GET[‘path’];

// create the completepath from these values
$completepath=(‘../operations/archived_runs/pywrf_output/’ . $domain . ‘/’ . $date_folder . ‘/’ . $path);
$images=glob($completepath . ‘/*png’);
$archived_data = [];
// loop
$step = 1;
for ($i = 0; $i < count($images); $i+=$step) {
$img = $images[$i];
$archived_data[] = [‘img’ => $img];
}

echo json_encode($archived_data);
[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 28.2022 — Not sure I followed all of that, but my suspicion is that you'll want to do a foreach() on the array returned by scandir() (ignoring the . directories and anything else that should be ignored), then maybe doing the glob() etc. on each directory?
×

Success!

Help @frncskn spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...