Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Downloading mysql Blobs

    I trying to download a BLOB from my web page i have successfully uploaded files to the database but when i'm downloading im encountering problems

    showfiles.php that list al the files in the DB table (this works properly)
    PHP Code:
    <?php
    // Database connection variables
        #connect to MySQL
        
    $conn = @mysql_connect("***""***","***")
        or die(
    "Could not Connect");

        
    #select the specified database
        
    $rs = @mysql_select_db("***"$conn)
        or die(
    "Could not select specified");

    $dbQuery "SELECT blobId, blobTitle, blobType ";
    $dbQuery .= "FROM myBlobs ";
    $dbQuery .= "ORDER BY blobTitle ASC";
    $result mysql_query($dbQuery) or die("Couldn't get file list");

    ?>

    <a href="http://www.devarticles.com"><img border="0" src="http://www.devarticles.com/dlogo.gif"></a>
    <table border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" width="100%">
    <tr>
    <td width="34%" bgcolor="#FF9900" height="21">
    <p style="margin-left: 10"><b><font size="2" face="Verdana" color="#FFFFFF">
    Description</font></b></td>
    <td width="33%" bgcolor="#FF9900" height="21">
    <p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">
    Type</font></b></td>
    <td width="33%" bgcolor="#FF9900" height="21">
    <p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">
    File</font></b></td>
    </tr>

    <?php
    while($row mysql_fetch_array($result))
    {
    ?>

    <tr>
    <td width="34%" bgcolor="#FFDCA8" height="21">
    <p style="margin-left: 10; margin-right: 10">
    <font face="Verdana" size="1">

    <?php echo $row["blobTitle"]; ?>

    </font>
    </td>
    <td width="33%" bgcolor="#FFDCA8" height="21">
    <p style="margin-left: 10">
    <font face="Verdana" size="1">

    <?php echo $row["blobType"]; ?>

    </font>
    </td>
    <td width="33%" bgcolor="#FFDCA8" height="21">
    <p style="margin-left: 10"><font face="Verdana" size="1">

    <a href="downloadfile.php?fileId=<?php echo $row["blobId"]; ?>">

    Download now
    </a></font>
    </td>
    </tr>

    <?php
    }
    echo 
    "</table>";
    ?>

    downloadfile.php causes me problems it outputs the error Invalid blobId specified
    PHP Code:
    <?php
    global $blobId;

    if(!
    is_numeric($blobId))
    die(
    "Invalid blobId specified");

    // Database connection variables
    #connect to MySQL
    $conn = @mysql_connect("****""***","***")
    or die(
    "Could not Connect");
    #select the specified database
    $rs = @mysql_select_db("***"$conn)
    or die(
    "Could not select specified");

    $dbQuery "SELECT blobType, blobData ";
    $dbQuery .= "FROM myBlobs ";
    $dbQuery .= "WHERE blobId = $blobId";
    $result mysql_query($dbQuery) or die("Couldn't get file list");

    if(
    mysql_num_rows($result) == 1)
    {
    $fileType = @mysql_result($result0"blobType");
    $fileContent = @mysql_result($result0"blobData");

    header("Content-type: $fileType");
    echo 
    $fileContent;
    }
    else
    {
    echo 
    "Record doesn't exist.";
    }

    ?>

  • #2
    New Coder
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The error that I see is that your showfiles.php script is using "fileId" as the variable name:
    Code:
    <a href="downloadfile.php?fileId=<?php echo $row["blobId"]; ?>">

    in downloadfile.php you are checking for the variable "blobId":
    Code:
    if(!is_numeric($blobId))
    die("Invalid blobId specified");
    The fact that you are relying on register globals makes my skin itch a little too, but I will make the assumption that you know about the security implications and that you know what you are doing.

    Cheers


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •