Jump to content


Photo

Quick question


  • Please log in to reply
4 replies to this topic

#1 Maverickb7

Maverickb7
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 23 April 2006 - 12:33 AM

Alright I've been looking for a way to get this done for some time and haven't had any lucky just yet. I post articles to my site every day and when posting a article a specific if I should include one of my image galleries within it. I specify the folder name for the gallery and then use that to list the gallery at the end of the article. Here is where I have a problem. Lets say I have a gallery in the folder "Narnia Screenshots" and within that folder I have another folder called "thumbs". The folder "thumbs" includes the thumbnails of each image.

What I want to know is how I would have my code look in X directory and display the filename of the first file within that folder. Anyone know how I would do this?

I've been seeing a lot of scandir should that be what I should research?

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 23 April 2006 - 12:40 AM

[!--quoteo(post=367557:date=Apr 23 2006, 01:33 AM:name=Maverickb7)--][div class=\'quotetop\']QUOTE(Maverickb7 @ Apr 23 2006, 01:33 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I've been seeing a lot of scandir should that be what I should research?
[/quote]

Either that or readdir()
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Maverickb7

Maverickb7
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 23 April 2006 - 12:52 AM

Alright, I've seem to have things working fine but I have one problem. Lets say I have 10 articles displayed on my websites front page. I have one bit of code that is being looped to display each article. Now somewhere along the line the it gets confused and displays info that should be for another article. Now after reviewing the code its safe to say that its because the variables are named the same for all articles causing the code to get confused. What I want to know is how I can make each variable unique? Each article has a unique ID so I was thinking that I could just name the variable whatever and put the ID at the end... but I don't know how to do that.

So I guess when it comes down to it what I want to know is how I would give a variable a name... but have that name include a variable? Anyone?

#4 Maverickb7

Maverickb7
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 23 April 2006 - 02:11 AM

Alright, I'm using the below code.

$dh  = opendir("/home/public_html/media/");

while (false !== ($filename = readdir($dh))) {
   ${$id}[] = $filename;
}

sort(${$id});
rsort(${$id});
echo ${$id}[0];
}

I'm using it to generate the filename of the first file within the media folder. Within my media folder is a folder called thumbs and for some reason its listing the folder name rather then the first file. Does anyone know how I can avoid this?

#5 Maverickb7

Maverickb7
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 23 April 2006 - 03:24 AM

[!--quoteo(post=367579:date=Apr 22 2006, 10:11 PM:name=Maverickb7)--][div class=\'quotetop\']QUOTE(Maverickb7 @ Apr 22 2006, 10:11 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Alright, I'm using the below code.

$dh  = opendir("/home/public_html/media/");

while (false !== ($filename = readdir($dh))) {
   ${$id}[] = $filename;
}

sort(${$id});
rsort(${$id});
echo ${$id}[0];
}

I'm using it to generate the filename of the first file within the media folder. Within my media folder is a folder called thumbs and for some reason its listing the folder name rather then the first file. Does anyone know how I can avoid this?
[/quote]
I've fixed it by adding:

if ($filename != "." && $filename != ".." && $filename != "s") { ${$id}[] = $filename; }

works great now!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users