Reputation: 97
I have some script which output the images, with an interval of 5 seconds, on a screen.
All images are in a directory called images/easter
.
The URL to display the webpage is http://'localhost'/index.php
.
In the index.php
I have a variable: $directory = 'images/easter/
.
We want users create a new image directory and upload pictures to it (eg images/holiday
).
The new images have to be displayed with a simple change in the url.
http://'localhost'/index.php?holiday
I think this can be done by URL parsing in PHP. But how to script this?
Thanks in advanced.
Upvotes: 0
Views: 236
Reputation: 511
You can use $_GET parameters.
URL :
http://'localhost'/index.php?q=holiday
Code :
$directory = 'images/'((isset($_GET['q']))?$_GET['q']:'');
or
if (isset($_GET['q']))
$directory = 'images/'.$_GET['q'];
else
$directory = 'images';
Upvotes: 0
Reputation: 97
Thanks so far for the answers.
We do not want to edit the files, so the change have to be in the URL from where the pictures are taken.
My knowledge of PHP is very limited.
Upvotes: 0
Reputation: 227
Use $_GET to retrieve the desired values from the URL. You'd have to adapt it slightly though. Maybe you want something like http://'localhost'/index.php?dir=holiday
. That way, you can use $_GET on dir.
PHP Form handling
Upvotes: 0
Reputation: 4502
just make your url something like
http://localhost/index.php?dir=holiday
or just
http://localhost/index.php
In your script do the following:
<?php
$directory = 'images/'.((isset($_GET['dir'])) ? $_GET['dir'] : 'easter');
But be sure to check weather the input is valid, so that it is not possible to output the content of a private folder.
If you want Urls like
http://localhost/holiday
you shold take a look at mod_rewrite
Upvotes: 1