0

Hello to everyone,
I have a mysql table

CREATE TABLE `tools_domuments` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(255) CHARACTER SET utf8 NOT NULL,
  `description` longtext CHARACTER SET utf8 NOT NULL,
  `filetype` varchar(255) CHARACTER SET utf8 NOT NULL,
  `document` longtext CHARACTER SET utf8 NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

In the column 'document' I am inserting the content of the files encoded with Base64Encode. I am doing this with an desktop app.
My issue is that I want a php file that when I execute it, to download a file that is stored in a specified row.
I have tried some samples but with do success.
Could someone help me with this?!

2
Contributors
2
Replies
21
Views
3 Years
Discussion Span
Last Post by klaus.veliu
0

Can we see at least ONE of those script samples? Maybe it just need minor tweakings.

Normally, if the query is successful, we can decode the row document like this

echo base64_decode($row['document']);

Edited by veedeoo: info added.

0

Thank you for your reply.
Here it is the code that I was testing:

<?php
    require_once("config.php");

    $item_id = stripslashes($_GET['item_id']);
    $item_id = mysql_real_escape_string($item_id);  
    settype($item_id, "integer");
    if ( $item_id < 1 ){
            include_once('error_sqli.php');
            exit();
    }

        $query = "SELECT tools_domuments.filename, tools_domuments.filetype, tools_domuments.document FROM tools_domuments WHERE tools_domuments.id = '$item_id';";       
        $result = mysql_query($query) or die('Error, query failed');
        list($name, $type, $content) =  mysql_fetch_row($result);
        $content = base64_decode($content);
        $type    = base64_decode($type);
        $name    = base64_decode($name);

        header("Content-Disposition: attachment; filename=\"$name\"");
        header("Content-type: $type");
        //header("Content-length: $size");
        print $content;

?>

I will also try the command that you suggested to me.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.