DeeDee
Members-
Posts
26 -
Joined
-
Last visited
DeeDee's Achievements
Newbie (1/14)
0
Reputation
-
Hey guys its been a while As I have said I will share this code on downloading files here (btw this is not complete but this is just a backbone idea of what it is, so expect some flaws on this) dataB.php <?php // if result returns false..... if ($result == 0) { echo "Dude, Where's my Files? <br>"; //...output this } else { //...output this if result returns at least 1 entry echo "<table border='1'> <tr> <td>FileEntry</td> <td>Filename</td> <td>Type</td> <td>Size(bytes)</td> <td>Time received</td> </tr>"; //iterate through the rows of the existing query for ($i = 0; $i < $rows; $i++) { $data = mysql_fetch_object($result); echo "<tr>"; echo "<td>" . $data->FileEntry. "</td>"; echo "<td>" . $data->Filename . "</td>"; echo "<td>" . $data->Filetype . "</td>"; echo "<td>" . $data->Filesize . "</td>"; echo "<td>" . $data->Received . "</td>"; echo "<td><a href='dataB.php?id=$data->id'>Collect here</a></td>"; echo "</tr>"; } echo "</table>"; } mysql_free_result($result); // releases memory mysql_close(); // closes database connection ?> dataA.php <?php $id = $_GET['id']; if ($id) { mysql_connect("myhost", "myroot", "") or die(mysql_error()); mysql_select_db("FileCollections") or die(mysql_error()); //generate queries $query = "SELECT Contents, Filetype, Filename, Filesize FROM FileData WHERE id=$id"; $result = mysql_query($query); $data = mysql_result($result, 0, "Contents"); $name = mysql_result($result, 0, "Filename"); $size = mysql_result($result, 0, "Filesize"); $type = mysql_result($result, 0, "Filetype"); // return output header("Content-type: $type"); header("Content-length: $size"); header("Content-Disposition: attachment; filename=$name"); echo $data; } ?> BTW Larry, If this has already been posted on the forum, then I apologize as I have tried to find an existing post of this otherwise I hope this will help any one in future. Thx
-
Hey guys just to give an update that I have managed to download the file with the contents, basically I used this piece of code mysql_fetch_object(); to accomplish my task. I'll provide the link here should anyone needs it in future. http://www.w3schools.com/php/func_mysql_fetch_object.asp My humble thanks to the people who helped and replied.
-
Hi Guys just to update I managed to have the file to be downloaded however it does not display the contents of the file I will display my new code here <?php ob_start(); include('connectme.php'); $query = "SELECT name, type, size, Content FROM Files"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $read = $row['name']; header("Content-length:" . $row['size'] . "<br>"); header("Content-type:" . $row['type'] . "<br>"); header("Content-Disposition: attachment; filename =" . basename($read) . "<br>"); echo $row['Content'] . "<br>"; readfile($read); } ob_clean(); //exit(); mysql_close(); ob_flush(); ?> Tips are appricated thank you
-
Ah byp, the final else from the first if statement is returned 'Error!!!' I was sure that this line header("Content-Disposition: attachment; name =" . $row['name']); was correct, however I don't have the appropiate book to learn from just the internet and some planning on my part. If there is a book that you can recommend me to learn more about downloading blobs via database I would be greatful. Thanks so far for your replys so far Jonathon.
-
Hi guys I would like to request some help on a problem I am trying to solve. I am trying to download files from a database but it is only reading the file else statement. So I went about creating this code shown here. <?php if (isset($_GET['id'])) { $id = intval($_GET['id']); if ($id <= 0) { die("Connection Failed"); } else { include('connectme.php'); } $query = "SELECT name, type, size, Content FROM Files WHERE id = '$id'"; $result = mysql_query($query) or die(mysql_error()); if ($result) { if (mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); header("Content-length:" . $row['size']); header("Content-type:" . $row['type']); header("Content-Disposition: attachment; name =" . $row['name']); echo $row['Content']; } } else { echo "Invalid ID"; } mysql_free_result($result); } else { echo "Error!!!"; } //mysql_close(); ?>
-
Hi guys I have a problem that I need some assistance with my database results is not displaying results properly for different users, leaving blank tuples in a row. Code is shown here (Ill explain a segment of code if anyone needs explaination they do not understand) Lets say I have already assigned my variables using post. <?php session_start(); include('db.php'); $UserID = $_SESSION['UserID']; $Firstname = $_POST['Firstname']; $GroupID = $_POST['GroupID']; $Surname = $_POST['Surname']; if ($UserID) { $query = "SELECT a.UserID, a.GroupID, b.Firstname, b.Surname FROM table a, table b WHERE a.UserID = b.UserID AND b.UserID LIKE '%$UserID%'"; $result = mysql_query($query); $row = mysql_fetch_array($result); while ($row = mysql_fetch_array($result)) { $UserID = mysql_real_escape_string($row['UserID']); $Firstname = mysql_real_escape_string($row['Firstname']); $Surname = mysql_real_escape_string($row['Surname']); $GroupID = mysql_real_escape_string($row['GroupID']); } $query2 = "INSERT INTO table2 (UserID, Forename, GroupID, Surname) VALUES('$UserID', '$Forename', '$GroupID', '$Surname')"; $run = mysql_query($query2) or die(mysql_error()); include('locate.php'); mysql_close(); } ?> FYI I have tested out SELECT query on mySQL and it works when the script is executed, the problem is however it does not display the results for all different logged in users. (If a simular post exists please redirect!!)