Solved

reading file from a directory?

Posted on 2002-05-09
2
144 Views
Last Modified: 2006-11-17
hai all,

I wanted to read a dir & choose a particular file.
I wrote as follows:
$dir=dir("/home/ftp/rf_auto");
    while($file=$dir->read()){
     if(substr($file,14,8)=="rf_auto2" && (substr ($file,-12,8)==substr($filename,-12,8))){
     $fcontents1=$file;
     exit();
     }

in this loop I wanted to exit the loop once I select the file($file).
How do I do this?

Thank u,
baska


0
Comment
Question by:baska
2 Comments
 

Author Comment

by:baska
ID: 6998418
//there should be one more closing bracket.
}
//my requirement is,it should not read until end of the dir
//how to implement the condition.

thank u
baska
0
 
LVL 32

Accepted Solution

by:
Batalf earned 50 total points
ID: 6998593
You should use break; instead of exit;

Exit; is used to exit the script, break is used to break out of a loop:

$dir=dir("/home/ftp/rf_auto");
   while($file=$dir->read()){
    if(substr($file,14,8)=="rf_auto2" && (substr ($file,-12,8)==substr($filename,-12,8))){
    $fcontents1=$file;
    break;
    }
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now