Forum Moderators: coopster

Message Too Old, No Replies

ASP fool in a PHP world

need some help with some basics

         

too much information

1:47 am on Aug 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a script in ASP that reads the contents of the directory the file is in and returns a file list in a specific format:

[domain.com...]
[domain.com...]
[domain.com...]
...

where the "http://www.domain.com/folder/" is supplied by the querystring.

Here's what I have been able to compile from online sources and where I have gone horribly wrong.

<?php

function GetFileList($dirname, $extensoes = FALSE, $reverso = FALSE)
{
if(!$extensoes) // only list image files
$extensoes = array("jpg", "png", "jpeg", "gif");

$filenames = array(); // to store the file names without extensions
$files = array(); // to store the file names with extensions
$dir = getcwd() . "/";
$loc = Request.querystring("URL") // I don't know how to grab a query string variable

while(false!== ($file = readdir($dir)))
{
// only grab image files
for ($i = 0; $i < count($extensoes); $i++)
{
if (eregi("\.". $extensoes[$i] ."$", $file))
{
$filenames[] = $file - $extensoes // I need the file name separate from the extension
$files[] = $file;
}
}
}
// close the handle
closedir($dirname);
// arrange the files
if ($reverso) {
rsort($files);
} else {
sort($files);
}
for ($i = 0; $i < count($files); $i++)
{
// I need to print the results to the screen
 echo "$loc$files,$filenames @br /@ \n";
}
}

?>

I appreciate any help, and I promise to go buy a PHP book as soon as possible! ;)

bilalak

9:16 am on Aug 12, 2003 (gmt 0)

10+ Year Member



What is the error, logical error of course?

I think you had a mistake in this line:

$filenames[] = $file - $extensoes;
If you like to strip the extension then you can use substr for this

Let me know if you could solve it or u need more clarification

too much information

12:04 pm on Aug 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks bilalak,

Actually there are two errors. The line you spotted and the other commented line at the top where I have no clue how to grab a querystring variable. (thus the VB line)

I'll take a look at 'substr', that's a Big help. Thanks!

This is all very confusing to me right now. I do all of my programming in ASP and have been thinking of learning PHP but I didn't expect to have to rush into it! ;)

btw, how does my 'echo' line look? I'm not sure what the '@br /@' do but this whole thing is pieces of things I found online to get me started.

hakre

2:48 pm on Aug 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi too much information,

the echo line looks a little strange. i think the at-sign is just a little freaky here and it should create an html tag, right?

so just take it this way:
echo "$loc$files,$filenames <br />\n";

too much information

6:15 pm on Aug 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



WOW, something just clicked, I'm starting to understand this stuff. I had no idea what those @'s did. I think what I ultimately need is to drop that tag all together:

echo "$loc$files,$filenames\n";

Someone told me PHP was easier than ASP, I don't know that I can argue one way or the other, but so far this script is about 1/3 smaller than the ASP version.

all I need now is to understand how to collect a variable form the querystring.

Thanks for all the help everyone

jatar_k

6:19 pm on Aug 12, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try these

parse_url [ca.php.net]
$_GET superglobal array [php.net]

depends on how you are doing things

I love the title of this thread, made me laugh ;)

too much information

6:42 pm on Aug 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I didn't make it back in time to edit my last post, but I put this together for the querystring variable:

$thisQuery = $_SERVER["QUERY_STRING"];
$queryValue = explode("=",$thisQuery);
$loc = $queryValue[1];

I'm going to try this when I get a chance (I'm not where I can test things right now), but if it looks funny to anyone, let me know.

btw, I'm only passing one variable.

jatar - glad I made you laugh, I though it was a fairly true statement. Kinda felt like I was a little overwhelmed at first, but I'm picking it up.

hpche

8:51 pm on Aug 12, 2003 (gmt 0)

10+ Year Member



If you just want a PHP equivalent of:
$loc = Request.querystring("URL")
then I think the simplest way to do that would just be like:
$loc = $_GET['URL'];

too much information

1:44 am on Aug 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh yea, that's much simpler! Thanks

Plus it will be easier to follow later since it is so similar to my other file.