0

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.

2
  • You can make your url like this http://'localhost'/index.php?q=holiday , and use $_GET['q'] for getting access to your parameter Commented Feb 21, 2014 at 9:36
  • How is the axact syntact? This will not work: $directory = 'images/'.((isset($_GET['q'])) ; with localhost/harald/index.php?q=test Commented Feb 21, 2014 at 11:01

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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.

Comments

0

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';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.