Yes, it is not easy task. but a difficult task gives us much Serotonin when it is solved.
Since you gave me the good code below for displaying list of directories and files by recursive way, I thought I can get my target which is downloading a directory if I insert downloading code each on the way of turning(recursive). but I don’t have the correct downloading code of directories although I have the correct downloading code of files
<?php
declare(strict_types=1);
error_reporting(-1);
ini_set('display_errors', '1');
$path = ".";
?><!doctype html><html lang="en">
<head>
<title> asdf </title>
<style>
body {background-color: #fafafa; color: #00f;}
.bd1 {border: solid 1px #ccc;}
.dib {display: inline-block;}
.fsl {font-size: large;}
.tac {text-align: center;} .tal {text-align: left;}
</style>
</head>
<body class="bgQ">
<h1>
<a href="https://www.php.net/manual/en/function.glob.php#92710">
Source
</a>
</h1>
<div class="mga tac">
<pre class="dib fsl fwb bgs tal bd1">
<?php
$dir_iterator = new RecursiveDirectoryIterator($path);
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
// could use CHILD_FIRST if you so wish
foreach ($iterator as $file)
{
echo "\n" .$file;
}
?>
</pre>
And the code below which download a file still has a problem.
if I find the solution for a directory downloading, then I like to challenge the downloading
of the whole directories and files using the recursive way.
Hi @joon1,
If you insist on doing this task with Php code then you are going to want to do this with FTP functions. Check out the manual page. There are also many code examples that may get you on your way.
I guess The quotes below means:
(1) this task is very difficult.
(2) although I succeed it with lucky, it will not work as I expected.
(3) FTP in PHP is also very difficult
I didn’t know downloading directories is this difficult when I post this question at first.
That doesn’t mean you just have to continue you know. Don’t fall into the sunken cost falacy of I’ve done so much now I should finish it.
Accept defeat, try something else
Look back at previous suggestions, many require a remote server. There are numerous companies that offer free servers which are excellent for practising and becoming knowledgeable in remote storage and retrieval.
Data transfer has been researched and refined. RSync is exceptionally fast because it transfers only the parts of a file that have changed and, zips while transfering the changes. Imagine trying to write that functionality! Grsync is the free graphical version available on all platforms.
Another example is using Git and Github, etc
There are also Free Graphical Ftp applications, my favourite is FileZilla making dragging and dropping directories very simple especially when only modified files are uploaded/downloaded.
Be aware there are many bad examples on the internet, look for examples with comments otherwise the author is afraid or incompetent to reply to any comments - I await your comments
I think the ob_clean is not the best example to perform your task.
The solution is to use a free online remote server, make this your priority for today