473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

choosing one file from dir

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
7 1816
> $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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: Fred Ma | last post by:
Hello, This is not a troll posting, and I've refrained from asking because I've seen similar threads get all nitter-nattery. But I really want to make a decision on how best to invest my time....
11
by: Jean de Largentaye | last post by:
Hi, I need to parse a subset of C (a header file), and generate some unit tests for the functions listed in it. I thus need to parse the code, then rewrite function calls with wrong parameters....
3
by: middletree | last post by:
I have a page which, according to the boss's instructions, needs to show one of two things, based on which radio button was chosen on the previous page. Because these 'things' are actually some...
4
by: Jonas Hei | last post by:
I need to decided between Standard and Enterprise Edition (Cost is a criteria - but its secondary to performance - <!--and I am not paying for it myself-->) The server spec under consideration:...
1
by: P Nishanthan | last post by:
Hi, My asp.net web application is working somthing with the data files which is located in the web server. i have to give the option to the user to select the file he wanted to process(files are...
19
by: hansBKK | last post by:
Upfront disclaimer - I am a relative newbie, just starting out learning about PHP, mostly by researching, installing and playing with different scripts. I am looking for a host that will provide...
3
by: guybenron | last post by:
Hey, I have a sort of petty-neurotic question, I'm kinda pedantic and like to keep my log directories clean, and this thing is bothering me to the point of actually posting a question (couldn't...
5
by: LayneMitch via WebmasterKB.com | last post by:
Code is suppose to choose a random name using 'event listeners'. The reference file is a file downloaded from the book's publisher "Sitepoint". I doubt that there is anything wrong with the file...
3
by: MC | last post by:
I'm developing an application that needs a large (up to 4 GB) amount of temporary file space on a local (not network-attached) disk. What are some good tactics to use in a C# program to make sure...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.