I need to read all the files in the directory using php. So I need return like this
array(
'content_type' => 'application/zip',
'suggested_name' => 'this_is_example.zip',
'protected_path' => 'download/this_is_example.zip'
),
My generate file like this:
$download_list = array();
if(is_array($PROTECTED_DOWNLOADS)) {
foreach ($PROTECTED_DOWNLOADS as $key => $download) {
// Create a new key
$new = uniqid('key',TRUE);
// get download link and file size
$download_link = "http://" . $_SERVER['HTTP_HOST'] . DOWNLOAD_PATH . "?key=" . $new . "&i=" . $key;
$filesize = human_filesize(filesize($download['protected_path']), 2);
$filename = ($download['suggested_name']);
// Add to the download list
$download_list[] = array(
'download_link' => $download_link,
'filename' => $filename,
'filesize' => $filesize
);
/*
* Create a protected directory to store keys in
*/
if(!is_dir('history')) {
mkdir('keys');
$file = fopen('history/.htaccess','w');
fwrite($file,"Generator");
fclose($file);
}
/*
* Write the key key to the keys list
*/
$file = fopen('history/keys','a');
fwrite($file,"{$new}\n");
fclose($file);
}
}
Now everything is working, but I have to enter these files myself before run it. How can I publish all the files from directory? Now I have like this:
$PROTECTED_DOWNLOADS = array(
array(
'content_type' => 'application/png',
'suggested_name' => 'example.png',
'protected_path' => 'download/example.png'
),
array(
'content_type' => 'application/txt',
'suggested_name' => 'this_is_example.txt',
'protected_path' => 'download/this_is_example.txt'
),
array(
'content_type' => 'application/zip',
'suggested_name' => 'this_is_example.zip',
'protected_path' => 'download/this_is_example.zip'
),
array(
'content_type' => 'application/rar',
'suggested_name' => 'this_is_example.rar',
'protected_path' => 'download/this_is_example.rar'
),
array(
'content_type' => 'application/docx',
'suggested_name' => 'this_is_example.docx',
'protected_path' => 'download/this_is_example.docx'
)
);
I tried with glob(), scandir() and readdir(), but I could not get the desired result. Thanks!