?
Solved

reading file from a directory?

Posted on 2002-05-09
2
Medium Priority
?
152 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 150 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

807 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