Reputation: 2323
I want to use php or xmlwebrequest to upload a file to the server and receive another file from back from the server after the upload is complete. I have a simple html form script for the user to select the file to upload, and I have another button to allow the user to select the download folder to place the new file received from the server.
The form I have created allows the user to navigate to the download folder, but it wants a file name to select in the local folder; this is a download, so the file would not be a file on the client computer, it's coming from the server.
Here's the html code:
<div class="h1_inf"><b>Upload/Download File</b></div><br><br>
<div class="z_01">
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload"><br><br>
<input type="submit" value="Upload File" name="submit">
</form><br>
<form action="dnload.php" method="get">
Select image to dnload:
<input type="file" name="fileToDnload" id="fileToDnload"><br><br>
</form>
</div>
Question: how can I select a download directory for a file to be received from the server. I'm open to using php or xmlwebrequest, but the form elements are pure html.
I know there are a lot of posts on this issue, and some have said that it cannot be done due to browser security, but there must be some way to let the user decide where to download a file from the server?
Upvotes: 0
Views: 114
Reputation: 6693
You can use glob()
to cycle through directories and get all extensions.
function searchFiles($path, $extension) {
$files = [];
foreach(glob("{$path}/*.{$extension}"), GLOB_BRACE) as $file) {
$files[] = array('name' => $file, 'size' => filesize($file));
}
}
You can then cycle through all the png images and output them for download:
<?php foreach(searchFiles('/images', 'png') as $image): ?>
<a download href='/images/<?= $image['name']; ?>.png' alt='<?= $image['size']; ?>'> Download <?= $image['name']; ?> </a>
<?php endforeach; ?>
Upvotes: 1