Jump to content

Folder Issue


evilgenius82

Recommended Posts

Hey everyone,

Im new here & also quite new to PHP.

I am currently creating a project which reads files from a directory & lists the file names and certain file attributes.

 

I have done quite well so far (in my opinion) but have come across a small issue.

I have created a folder in the web directory & want to read files from it.

Unfortunately the script is not reading files from it & is still reading files from root.

 

I cant seem to fix at after playing around with the code for ages now.

 

Any help would be much appreciated!

 

<? 
$dir_name = './file_pool/';                                                  //name of directory path.

$iterator = new DirectoryIterator(dirname($dir_name));   //Instance DI
foreach ($iterator as $fileinfo) {
   
   $link =( $fileinfo->getPathname());                                //store path name as variable
   
   if (!$fileinfo->isDot()) {                                                   //Removes the . & .. 
   if (!$fileinfo->isDir()) {                                                    //Removes other directories 
   
   
      
   echo '<tr>';
    echo '<td>', $fileinfo->getBasename() . '</td>   
         <td>',  $fileinfo->getExtension() .   '</td>
         <td>',  $fileinfo->getSize() . '</td>
         <td>',  date("F d Y ", filemtime($fileinfo)). '</td>
         <td>',  '<a href=" ', $dir_name . $fileinfo ,' ">Download <a/> '  . '</td>
         <td>',hash_file('md5', $fileinfo).  '</td>' ;
   
   
   }
   }   
   
}

  
?>        

 

Link to comment
Share on other sites

Hi everyone,

I managed to fix it!

 

Below is the code:

 

$iterator = new DirectoryIterator($dir_name);   //Instance DI
foreach ($iterator as $fileinfo) {

$link =( $fileinfo->getPathname());             //store path name as variable

if (!$fileinfo->isDot()) {                //Removes the . & .. 
if (!$fileinfo->isDir()) {               //Removes other directories 



echo '<tr>';
    echo '<td>', $fileinfo->getBasename() . '</td>   
         <td>',  $fileinfo->getExtension() .   '</td>
         <td>',  $fileinfo->getSize() . '</td>
         <td>',  date("F d Y ", filemtime($link)). '</td>
        
         
	 <td>',  '<a href=" ', $dir_name , '/' , $fileinfo ,       ' ">Download <a/> '  . '</td>

	 <td>',hash_file('md5', $link).  '</td>' ;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.