Jump to content

[SOLVED] problem reading dir


adam291086

Recommended Posts

hello,

 

i am trying to read a directory and list all the files. I keep getting the error messages

 

 

Warning: opendir(http://www.bcyorkshire.co.uk/admin/entry_form/form/) [function.opendir]: failed to open dir: not implemented in /homepages/30/d227915861/htdocs/admin/rte/view_uploaded_items/view_entry_forms.php on line 60

 

this is my code

 

<?php
error_reporting(E_ALL);
$dir ="http://www.bcyorkshire.co.uk/admin/entry_form/form/";
if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
    ?>  

 

I know the directory existing any thoughts?

Link to comment
https://forums.phpfreaks.com/topic/106157-solved-problem-reading-dir/
Share on other sites

ok i have implemented some ftp stuff.

 

$c = @ftp_connect($ftpServer); 

$l = @ftp_login($c, $ftpUser, $ftpPass); 

$currDir = ftp_pwd($c);  
$contents = ftp_nlist($c, "admin/entry_form/form/");

//loop through array of files and folders 

for($i = 0; $i < sizeof($contents); $i++) 

{ 

// We will remove the parent directory (if any) 

// from the name of the file that gets displayed 

$trimFile = str_replace("$currDir", "", $contents[$i]); 



// Remove any forward slash at front of name 

$trimFile = str_replace("^/", "", $trimFile); 

?>
     

<a href ="http://www.bcyorkshire.co.uk/admin/entry_form/form/<?php echo $trimFile?>"><?php echo $trimFile?> </a>
<br />
<br />
<div class = "maintext">
Link for the document: http://www.bcyorkshire.co.uk/admin/entry_form/form/<?php echo $contents[$i]?>
</div>
<br />
<br />
<br />
<?php
}
ftp_close($c);
?>

 

this works fine. But i am trying to get the file name in its own. I thought using ftp_pwd would do it but that only remove bcyorkshire.co.uk and leave behine adminentry_formform/filename. It removes the /'s but not everything else.

 

Also how do i remove the . and .. files

this is what i have got to remove the . and .. but it doesn't work. I don't get any errors but i still get the . and .. links appearing

 

$c = @ftp_connect($ftpServer); 

$l = @ftp_login($c, $ftpUser, $ftpPass); 

$currDir = ftp_pwd($c);  
$contents = ftp_nlist($c, "admin/entry_form/form/");





//loop through array of files and folders 

foreach($contents as $file) 

{ 
      if ($file!='.'&&$file!='..') {

// We will remove the parent directory (if any) 

// from the name of the file that gets displayed 

$trimFile = str_replace("admin/entry_form/form/", "", $file); 


// Remove any forward slash at front of name 

$trimFile = str_replace("^/", "", $trimFile); 



?>
     

<a href ="http://www.bcyorkshire.co.uk/admin/entry_form/form/<?php echo $trimFile?>"><?php echo $trimFile?> </a>
<br />
<br />
<div class = "maintext">
Link for the document: http://www.bcyorkshire.co.uk/admin/entry_form/form/<?php echo $file?>
</div>
<br />
<br />
<br />
<?php
}
}
ftp_close($c);

Try it this way.

 

<?php

$c = @ftp_connect($ftpServer); 

$l = @ftp_login($c, $ftpUser, $ftpPass); 

$currDir = ftp_pwd($c);  
$contents = ftp_nlist($c, "admin/entry_form/form/");





//loop through array of files and folders 

foreach($contents as $file) 

{ 
     if($file == "." || $file == "..")
           continue; //Skip current

// We will remove the parent directory (if any) 

// from the name of the file that gets displayed 

$trimFile = str_replace("admin/entry_form/form/", "", $file); 


// Remove any forward slash at front of name 

$trimFile = str_replace("^/", "", $trimFile); 



?>
     

<a href ="http://www.bcyorkshire.co.uk/admin/entry_form/form/<?php echo $trimFile?>"><?php echo $trimFile?> </a>
<br />
<br />
<div class = "maintext">
Link for the document: http://www.bcyorkshire.co.uk/admin/entry_form/form/<?php echo $file?>
</div>
<br />
<br />
<br />
<?php
}
}
ftp_close($c);

?>

 

 

Take also a look into basename(). Could simplify your work.

 

Orio.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.