Welcome, Guest. Please login or register.
Did you miss your activation email?
February 13, 2012, 01:27:16 AM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
149700 Posts in 21103 Topics by 7538 Members
Latest Member: ionline
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: BLOBS are corrupted with template data  (Read 552 times)
andreww

Offline Offline

Posts: 4


« on: February 07, 2010, 06:31:14 AM »

I have an upload form that uploads files (txt,pdf,bin etc..) to a MYSQL table as a blob.  The files are valid when saved in the table as a blob.  My download script retrieves the data, but when it's extracted as an attachment, it saves it with template html code corrupting the file.  Is there anyway to strip/filter out the HTML/template code from the attachment when it prompts to save the file?

Thanks.
Logged
Argos
Moderator
**
Offline Offline

Posts: 2084


WWW
« Reply #1 on: February 07, 2010, 12:07:38 PM »

What is a blob? What upload and download scripts do you mean? Are you talking about WebsiteBaker at all?
Logged

Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
WB Showcase: http://www.mywebsitebaker.com/pages/showcase.php?v&category_id=1242&count=30
----------------------------------------------------------------
Please don't request personal support, use the forums!
andreww

Offline Offline

Posts: 4


« Reply #2 on: February 07, 2010, 06:33:04 PM »

BLOBS (Binary Large Objects) is a data type in a MYSQL database.  I have the following forms/code inside a Web Baker template.  See below

Upload a file form -

<form method="POST" enctype="multipart/form-data" action="upload.php">
    <table width="350" cellspacing="1" cellpadding="1" border="0" class="box">
        <tbody>
            <tr>
                <td width="246"><input type="FILE" name="userfile" id="username" /></td>
                <td width="80"><input type="submit" value="Upload" name="upload" /></td>
            </tr>
        </tbody>
    </table>
</form>

///---Inserts the file into the MYSQL database

include 'library/config.php';
include 'library/opendb.php';
//replace the above two string's with your database specific values
$sql="SELECT id, name ";
$sql .="FROM Upload.upload";
$sql_results = mysql_query($sql);

echo "<TABLE BORDER=1 cellspacing=0 cellpadding=5>";
echo "<TR><TD>File Link</TD><TD>Name</TD></TR>";

while ($rs = mysql_fetch_array($sql_results))
{
    echo "<TR><TD><a href=download.php?id=".$rs[0].">". $rs[1]."</a></TD>";    
    echo "<TD>". $rs[1] ."</TD>"; //Name
    }
    echo "</table>";
echo "<P></P>* Click on the file name to download the file";

//----Downloads the file stored in the MYSQL Database.  When this happens and this code is incorporated in a web baker template the attachment/save as file is corrupted with template data - corrupting the file in the process.

include 'library/config.php';
include 'library/opendb.php';
$id=$_GET['id'];
$sql = "SELECT content, type, name, ";
$sql .="size FROM Upload.upload WHERE id=$id";
$result = @mysql_query($sql);
mysql_result($result, 0);
$data = @mysql_result($result, 0, "content");
$type = @mysql_result($result, 0, "type");
$name = @mysql_result($result, 0, "name");
$size = @mysql_result($result, 0, "size");
include 'library/closedb.php';
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;

//---

The download code above extracts the file correctly, but is corrupted with the template data when it saves the file.  Is there anyway to filter out the web baker template code from the attachment.  I modified the code template to a blank template, but a small piece of code still gets attached to the attachment if that makes sense upon downloading and saving the file from the database.  Any help would be appreciated.

Thanks.

Logged
Argos
Moderator
**
Offline Offline

Posts: 2084


WWW
« Reply #3 on: February 07, 2010, 11:58:13 PM »

You talk about "Webbaker" and about a folder called "/library". This is the forum about WebsiteBaker and there is no folder called /library in websitebaker. Are you talking about websitebaker?

Even if so, your question seems to have little to do with WB, it looks like some general PHP/database related problem...
Logged

Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
WB Showcase: http://www.mywebsitebaker.com/pages/showcase.php?v&category_id=1242&count=30
----------------------------------------------------------------
Please don't request personal support, use the forums!
andreww

Offline Offline

Posts: 4


« Reply #4 on: February 08, 2010, 04:11:33 PM »

The code above works fine outside of websitebaker.  When this code is incorporated inside a WebsiteBaker code template it spits out the contents with the attachment, corrupting it. It's not a code/php issue.  It's to do with the templates outputting page content.  I need the blank template for example to output absolutely nothing if it's possible.  It seems like the blank template still outputs a one line of code corrupting the file.
Logged
Argos
Moderator
**
Offline Offline

Posts: 2084


WWW
« Reply #5 on: February 08, 2010, 04:16:21 PM »

Maybe Code2 works better? http://www.websitebakers.com/pages/admin/core-replacements/code-2.php
Logged

Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
WB Showcase: http://www.mywebsitebaker.com/pages/showcase.php?v&category_id=1242&count=30
----------------------------------------------------------------
Please don't request personal support, use the forums!
andreww

Offline Offline

Posts: 4


« Reply #6 on: February 08, 2010, 05:06:34 PM »

Thanks.  It's resolved. It had everything to do with the template I was using.
Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!