By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,636 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,636 IT Pros & Developers. It's quick & easy.

choosing one file from dir

P: n/a
hello and please excuse my clumsy english.
I'm really fresh in php (just want to make one small script for myself,
haven't fount such on net) and now I'm struggling with "calling one file
from some directory".

here is case:
have 10 dirs with picts, every dir have one subdir with thumbs.
have file with name of dir and owner of pics.

$f = fopen('autori.inc', 'r');
while ($line = fgets($f, 4096)) {
list($dir, $ime) = split("\|", htmlspecialchars($line));
$album = $dir;
$autor = $ime;

now, I would like to print one picture form each directory above the
name of the owner...

$handle = fopen("$album/thumb/*.jpg", "wb");

and, as can you see, I have no idea how to get that file... better to
say, I have ideas, but wrong.

here came place where I will use that image.

echo "<p class=\"image\"><img src=\"$handle\" alt=\"$autor\"
height=\"64\" border=\"0\"></p>\n";
echo "<p class=\"autor\"><a class=\"autor\"
href=\"album.php?album=$album&amp;autor=$autor\">$ autor</a></p>\n";
any suggestion? tip?

tnx.

Janko

--
Jan_ko?
--
Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
> $handle = fopen("$album/thumb/*.jpg", "wb");


huuuuh.... ok, that won't be "fopen" and definitely won't be "w"...
at least I have learned how to create "empty jpeg" :))

--
Jan_ko?
--
Jul 17 '05 #2

P: n/a
see readdir instead of fopen

http://ca.php.net/manual/en/function.readdir.php

--
"JaNE" <no****@mail.dot> wrote in message
news:1g8l3kk.gudoce1rr09iwN%no****@mail.dot...
$handle = fopen("$album/thumb/*.jpg", "wb");


huuuuh.... ok, that won't be "fopen" and definitely won't be "w"...
at least I have learned how to create "empty jpeg" :))

--
Jan_ko?
--

Jul 17 '05 #3

P: n/a
JaNE wrote:

hello and please excuse my clumsy english.
I'm really fresh in php (just want to make one small script for myself,
haven't fount such on net) and now I'm struggling with "calling one file
from some directory".

here is case:
have 10 dirs with picts, every dir have one subdir with thumbs.
have file with name of dir and owner of pics.

$f = fopen('autori.inc', 'r');
while ($line = fgets($f, 4096)) {
list($dir, $ime) = split("\|", htmlspecialchars($line));
$album = $dir;
$autor = $ime;

now, I would like to print one picture form each directory above the
name of the owner...

$handle = fopen("$album/thumb/*.jpg", "wb");

and, as can you see, I have no idea how to get that file... better to
say, I have ideas, but wrong.

here came place where I will use that image.

echo "<p class=\"image\"><img src=\"$handle\" alt=\"$autor\"
height=\"64\" border=\"0\"></p>\n";
echo "<p class=\"autor\"><a class=\"autor\"
href=\"album.php?album=$album&amp;autor=$autor\">$ autor</a></p>\n";


$f = fopen('autori.inc', 'r');

while ($line = fgets($f, 4096)) {
list($albun, $autor) = split("\|", htmlspecialchars($line));

$thumbimage = "";

$d = opendir("$album/thumb/"); //open directory
while($filename = readdir($d)){ //read files
if (preg_match("/\.jpg$/i", $filename)) { //get first jpeg
$thumbimage = $filename;
break; //stop going through directory if jpeg is found
}
}
closedir($d);

//write image code if jpg was found
if (strlen($thumbimage) > 0)
echo "<p class=\"image\"><img src=\"$album/thumb/$thumbimage\"
alt=\"$autor\" height=\"64\" border=\"0\"></p>\n";

//link to gallery (NOTE: &amp; has been replaced with "&" in link
echo "<p class=\"autor\"><a class=\"autor\"
href=\"album.php?album=$album&autor=$autor\">$auto r</a></p>\n";
}

This UNTESTED code should work, I think. You should read up on any functions
you're not familiar with and add some proper error handling. (i.e. in the code
above you'll get an error with closedir() if there was a problem with
opendir()).

Regards,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #4

P: n/a
Shawn Wilson <sh***@glassgiant.com> wrote:

This UNTESTED code should work, I think. You should read up on any
functions you're not familiar with and add some proper error handling.
(i.e. in the code above you'll get an error with closedir() if there was a
problem with opendir()).


Tnx Shawn. that helped a lot.
and yes... I should read, but what if I don't understand explanation of
function? I know I need to start from the basics, if I want to be php
programer, but case is that I'm photographer that just want to have one
small simple script... have found a lot of them on net, but none
satisfied me, so... here it is: me coding... (and *that* is joke:))

tnx again

--
Jan_ko?
--
Jul 17 '05 #5

P: n/a
JaNE wrote:

Shawn Wilson <sh***@glassgiant.com> wrote:

This UNTESTED code should work, I think. You should read up on any
functions you're not familiar with and add some proper error handling.
(i.e. in the code above you'll get an error with closedir() if there was a
problem with opendir()).


Tnx Shawn. that helped a lot.
and yes... I should read, but what if I don't understand explanation of
function? I know I need to start from the basics, if I want to be php
programer, but case is that I'm photographer that just want to have one
small simple script... have found a lot of them on net, but none
satisfied me, so... here it is: me coding... (and *that* is joke:))


If you have trouble understanding a function, I find it helps to read the
comments on the manual page, try the function in test scripts and/or ask about
it here. Good luck with your script,

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #6

P: n/a
Shawn Wilson <sh***@glassgiant.com> wrote:

If you have trouble understanding a function, I find it helps to read the
comments on the manual page, try the function in test scripts and/or ask about
it here. Good luck with your script,


tnx it is working fine...
temporary exhibition is on-line (agram.cc/galeria). now just some more
css fine-tuning and will be ready to be shifted on my real site.
the only problem left is how to made that script working as module for
cms I did choose...

--
Jan_ko?
--
Jul 17 '05 #7

P: n/a
JaNE wrote:

Shawn Wilson <sh***@glassgiant.com> wrote:

If you have trouble understanding a function, I find it helps to read the
comments on the manual page, try the function in test scripts and/or ask about
it here. Good luck with your script,


tnx it is working fine...
temporary exhibition is on-line (agram.cc/galeria). now just some more
css fine-tuning and will be ready to be shifted on my real site.
the only problem left is how to made that script working as module for
cms I did choose...


Glad it's working for you. I forgot to mention you should use url_encode() on
variables you're sending in a link. Otherwise, if there are spaces, &s, ?s,
etc. you'll get an error on some browsers.

//write image code if jpg was found
if (strlen($thumbimage) > 0)
echo "<p class=\"image\"><img
src=\"".url_encode($album)."/thumb/".url_encode($thumbimage)."\"
alt=\"$autor\" height=\"64\" border=\"0\"></p>\n";

//link to gallery (NOTE: &amp; has been replaced with "&" in link
echo "<p class=\"autor\"><a class=\"autor\"

href=\"album.php?album=".url_encode($album)."&auto r=".url_encode($autor)."\">$autor</a></p>\n";

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.