File save
how can we save the multiple files in one compiler so it will be easy to use?
2 Answers
3 years ago by Shakuntala
@Shakuntala When you click on run button the code you have written will be saved to server.
Is that you are looking for or anything else?
3 years ago by OneCompiler
The question actually is not clear, and there're missing infos like the used backend-language. However, I assume, you have an HTML-Form and you want to accept multi files and save them locally for further usage. Here's a sample code does the job.
<?php
if (isset($_POST["submit"])) {
$files = $_FILES['files'] ?? '';
foreach ($files['name'] as $key => $value) {
$name = $files['name'][$key];
$tmp_name = $files['tmp_name'][$key];
$size = $files['size'][$key];
$error = $files['error'][$key];
$type = $files['type'][$key];
move_uploaded_file($tmp_name, "uploads/$name");
}
}
?>
<form method="post" enctype="multipart/form-data">
<div style="margin-bottom: 1rem;">
<label for="files" style="display: block; margin-bottom: 1rem;">Choose file(s):</label>
<input type="file" name="files[]" id="files" multiple>
</div>
<input type="submit" name="submit">
</form>
Create a uploads folder, which will store locally your uploaded files/images.
You may concern files validation before storing them on the server or locally.
Good luck :)
3 years ago by MaMo20