[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Direct access by querystring

Posted on 2009-04-20
1
Medium Priority
?
237 Views
Last Modified: 2012-05-06
I'm totally unknown at  PHP and need a little function. I have this (shortened down) script,

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$path = "/var/spool/ast/mo";
$dir_handle = @opendir($path) or die("Unable to open $path");

$filelist = Array();
while ($file = readdir($dir_handle))
{
      $filelist[] = $file;
}

foreach ($filelist as $file)
{
      echo "<a href='/mo/$file'>$file</a><br/>";
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Let say that the php file is named files.php. I want the script to hit correct filename directly by typing files.php?file=filename.txt
Of course there are no result if the file does not exist. If the file exist, it load it as if i was clicked the hyperlink in the list.

Thank's in advanced
0
Comment
Question by:dingir
1 Comment
 
LVL 5

Accepted Solution

by:
AtanAsfaloth earned 1200 total points
ID: 24184050
Hi dingir,

The following code snippet should work, though it is untested. Insert your script at the end

~Atan
if (isset($_GET['file'])) {
	//Filename was supplied
	if (file_exists("/mo/".$_GET['file'])) {
		//File exists, go directly to file
		header("Location: /mo/".$_GET['file']);
		//Do not execute rest of script
		exit;
	}
}
 
//No filename supplied or filename was invalid
//Display filelist

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month20 days, 11 hours left to enroll

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question