Jump to content
Larry Ullman's Book Forums

DeeDee

Members
  • Content Count

    26
  • Joined

  • Last visited

Community Reputation

0 Neutral

About DeeDee

  • Rank
    Member
  1. 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
  2. Thanks HS I am sorry if I have mistreated your understanding in anyway. I can send an update of the written code to provide a example to anyone who wishes to learn about downloading blogs if that is okay with Larry
  3. 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.
  4. Yeah I do have files stored as blobs in the database but when I echo out its contents nothing is returned. I have already written data in the textfile but nothing is returned. I don't understand what I have done wrong but I'll have another look on fread to see if it works.
  5. 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
  6. I have restructed the code to grab the output and it returns 1 and 2. I will make adjustments to my code and let you know of my progress soon. Thanks Jon
  7. 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.
  8. It should return the contents of the file and prompt you with a download.
  9. 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(); ?>
  10. Apparently that line you told me to delete actually solved it thank you HartleySan. To answer your question on what I am doing I am selecting values from a table and then inserting them into a new table. I hope this answers your question.
  11. 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!!)
  12. Yeah I just changed back Log to datetime last night and it worked thank you both, how can i display the date and time onscreen? Say I have written the query already do I use the variable like this: echo $row['log']; or as a session echo $_SESSION['log']; Thanks
  13. I have replaced the datetime with timestamp and still does not update, but nonetheless I appricate the information you told me on timestamp, Thank you Matt.
  14. I've tried this as you said HartleySan, it still does not update the date, FEI(For Everyones Information) I am using datetime for the log function but I do not think it matters. Thanks for the suggesstion though if you do have another on mind I will welcome it.
×
×
  • Create New...