Solved

reading file from a directory?

Posted on 2002-05-09
2
147 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
insert into database through form with dynamic fields. 2 28
preventing spam with mailto 22 31
php checkbox validation 5 27
How do I fix this UPDATE error? 7 22
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

776 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