View Full Version : Retrieve and display attachments from database
matt3830
09-01-2008, 12:09 AM
I'm trying to retrieve the 10 most recent attachments on an outside page. My attachments are in files. This is what I've come up with so far, but I don't know what the path is to the images and how to display them. Any suggestions?
<?php
$result = mysql_query("SELECT * FROM attachment ORDER BY dateline DESC LIMIT 0,10", $connection);
if (!$result) {
die("Database query failed: " . mysql_error());
}
while ($row = mysql_fetch_array($result)) {
echo "<img src=\"/attachmentpath/" . $row[4] . "/><br />";
}
?>
Eikinskjaldi
09-01-2008, 12:40 AM
The attachment table will define the type of attachment.
The actual attachments live in
baseaddress/attachments/u/s/r/i/d/attachmentid.attach
The user ID is broken into individual digits as directories, so if you have userid 603 and an attachment id of 500 then it will live in
attachments/6/0/3/500.attach
There is also an attendant 500.thumb
matt3830
09-01-2008, 12:53 AM
Thanks, so I have the path, but how do you display .attach?
Dismounted
09-01-2008, 06:40 AM
".attach" is just a temporary extension. The content of this ".attach" file is the actual file.
Eikinskjaldi
09-01-2008, 10:39 PM
Query the attachment table to see what kind of file it actually is, and then convince php to handle the file correctly. This may involve moving the file to /tmp with the appropriate suffix, or...well...something else. php/file system interactions are not my forte.
Dismounted
09-02-2008, 07:49 AM
Basically, you just need to send the correct headers to the browser.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.