How get all the PDF files from directory and sub directory


For check pdf files in directory and sub directory

First we have to read folder and we will get directory and file name from folder.

then we will check is directory or not.

if we get directory then we again call the same function for get sub directory and file from current directory

and we will separate pdf file name from file extension.

Following code will help you for get pdf file list from mentioned directory name or we can also get all files from directory

$directory = 'typo3/fileadmin';

function expandDirectories($base_dir) {

    $directories = array();

    foreach(scandir($base_dir) as $file) {
		
        if($file == '.' || $file == '..') continue;

        $dir = $base_dir.DIRECTORY_SEPARATOR.$file;

        if(is_dir($dir)) {
            $directories = array_merge($directories, expandDirectories($dir));
        }else{
            if(strstr($dir,".pdf")){
                $directories []= $dir;
            }
        }
    }
    return $directories;
}

$directories = expandDirectories($directory);

print_r($directories);

You will get list of pdf file with directory name.

i hope it will work for you πŸ™‚ njoy πŸ˜‰

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

How to download image, PDF, Excel in php


 
How to download image using in php,
How to download PDF using in php,
How to download Excel using in php,
How to download CSV using in php
How to download PSD using in php

For download images, pdf, excel, zip, csv, tiff, bmp, PSD, ico using php then you can use below code.

$inPath = "IMAGE_ROOT_PATH";
$outPath = "IMAGE_NAME";

$fullPath = $inPath.$outPath;
 
	$tmp = explode(".",$outPath);
	$fsize = filesize($fullPath);

	switch ($tmp[count($tmp)-1]) {
	
	  case "pdf": $ctype="application/pdf"; break;
	  case "exe": $ctype="application/octet-stream"; break;
	  case "zip": $ctype="application/zip"; break;
	  case "docx":
	  case "doc": $ctype="application/msword"; break;
	  case "csv":
	  case "xls":
	  case "xlsx": $ctype="application/vnd.ms-excel"; break;
	  case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
	  case "gif": $ctype="image/gif"; break;
	  case "png": $ctype="image/png"; break;
	  case "jpeg":
	  case "jpg": $ctype="image/jpg"; break;
	  case "tif":
	  case "tiff": $ctype="image/tiff"; break;
	  case "psd": $ctype="image/psd"; break;
	  case "bmp": $ctype="image/bmp"; break;
	  case "ico": $ctype="image/vnd.microsoft.icon"; break;
	  default: $ctype="application/force-download";
	}
	
	header("Pragma: public"); // required
	header("Expires: 0");
	header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
	header("Cache-Control: private",false); // required for certain browsers
	header("Content-Type: $ctype");
	header("Content-Disposition: attachment; filename=\"".$outPath."\";" );
	header("Content-Transfer-Encoding: binary");
	header("Content-Length: ".$fsize);
	ob_clean();
	flush();
	readfile($fullPath);
	die;

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya