473,732 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.i nc', 'r');
while ($line = fgets($f, 4096)) {
list($dir, $ime) = split("\|", htmlspecialchar s($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.ph p?album=$album& amp;autor=$auto r\">$autor</a></p>\n";
any suggestion? tip?

tnx.

Janko

--
Jan_ko?
--
Jul 17 '05 #1
7 1843
> $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.do t> wrote in message
news:1g8l3kk.gu doce1rr09iwN%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.i nc', 'r');
while ($line = fgets($f, 4096)) {
list($dir, $ime) = split("\|", htmlspecialchar s($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.ph p?album=$album& amp;autor=$auto r\">$autor</a></p>\n";


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

while ($line = fgets($f, 4096)) {
list($albun, $autor) = split("\|", htmlspecialchar s($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($thumbi mage) > 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.ph p?album=$album& autor=$autor\"> $autor</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***@glassgian t.com
http://www.glassgiant.com
Jul 17 '05 #4
Shawn Wilson <sh***@glassgia nt.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***@glassgia nt.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***@glassgian t.com
http://www.glassgiant.com
Jul 17 '05 #6
Shawn Wilson <sh***@glassgia nt.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***@glassgia nt.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($thumbi mage) > 0)
echo "<p class=\"image\" ><img
src=\"".url_enc ode($album)."/thumb/".url_encode($t humbimage)."\"
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.ph p?album=".url_e ncode($album)." &autor=".url_en code($autor)."\ ">$autor</a></p>\n";

Shawn
--
Shawn Wilson
sh***@glassgian t.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
4101
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. I'm not interested on which language is better in *general*, just for my purpose. My area of research is in CAD algorithms, and I'm sensing the need to resort to something more expedient than C++, bash scripting, or sed scripting.
11
9610
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. What I call "shaking the broken tree" :) I chose to make my UT-generator in Python 2.4. However, I am now encountering problems in choosing the right parser for the job. I struggle in choosing between the inappropriate, the out-of-date, the...
3
3599
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 chunks of code which contain sql queries, loops, etc., I think it might be best to put each of them into an include. Will this work: <%If strReports = "Detailed" then%> <!-- #INCLUDE FILE="builddetailedreport.asp" -->
4
2381
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: Dual Xeon, 1GB RAM, 36GB - RAID 1 (Dell PowerEdge 1850). Application: Windows 2003 Std Server, ASP.NET, MS SQL Server 2000 based data driven web application.
1
968
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 in web server). how can i do this? Thanks in advance. Regards, P.Nishanthan
19
2577
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 the right environment for this - running a wide variety of PHP applications. I realise that security is also important, but for now flexibility is more important to me. Note that I'm **not** looking for people to recommend hosting companies, I...
3
2223
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 find any post about this..). My application has two types of components: daemons and regular ones that are run every on crontab. Because the log structure is very similar, I want both to use the same logging configuration file.
5
1336
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 itself. There has to be something wrong with the code or my referencing of the file (the file is in the same directory as the code). Not sure, but here's the code: <html><head><title>Prob.4</title> <style type="text/css"> #textfield...
3
2606
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 the swap space is suitable? There can be some interaction with the user to choose the swap file location, but the more the program can find out about it, the better.
0
8773
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9445
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9234
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6733
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.