Hellooo
I have some code that allows a user to upload documents (text, word, PDF). The documents ares stored in a folder directory and the names of the files are created before being inserted into a database column. The document names are displayed in a table format and when i click an individual file, the contents of the file is displayed. All good! But I would now like to have another button that when pressed will take ALL the names from DB column and fetch ALL the corresponding documents (the actual documents, not just the text names) form the directory and display them all in ONE document. So basically, I have a table with a column (file) storing document names and i want to retrieve the actual documents from the hard drive and display them in a single document.
The code for uploading the documents is below (this part is ok). I also have some other code I haven;t included.
[php]<?php
include_once("…/config/connectDB.php");
if (isset($_POST[‘buttonUpload’])) {
$file = rand(1000, 100000) . "-" . $_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_type = $_FILES['file']['type'];
$folder = "Master Folder/";
$new_file_name = strtolower($file);
$final_file = str_replace(' ', '-', $new_file_name);
if (move_uploaded_file($file_loc, $folder . $final_file)) {
$sql = "INSERT INTO applications(file) VALUES('$final_file')";
mysqli_query($link, $sql);
?>
<script>
alert('Successfully uploaded');
window.location.href = 'application.php?success';
</script>
<?php
} else {
?>
<script>
alert('error while uploading file');
window.location.href = 'application.php?fail';
</script>
<?php
}
}
?>[/php]
Displaying the table and file names in a table. Clicking a file name shows the content of that document only.
[php] $sql = “SELECT * FROM applications”;
$result_set = mysqli_query($link, $sql);
while ($row = mysqli_fetch_array($result_set)) {
?>
<?php
}
?>[/php]
I was trying something like below to retrieve and display all the documents but was being shown only the names in the DB
[php]
if (isset($_POST[‘getAllResumes’])) {
$sql = “SELECT file FROM applications”;
$result = mysqli_query($link, $sql);
if (!($result)) {
die(mysqli_error($link));
} else {
while ($row = mysqli_fetch_array($result)) {
echo $row['file'];
}
}
}[/php]