Search : in
By :

Unable to download file from mysql database

Last answer on Jun 9, 2009 8:09:21 am BST MYSQLPHP, on Jun 8, 2009 9:24:07 am BST 
 Report this message to moderators

Hello friends,

i wanted to upload pdf file into mysql database and and when user click a line on the page particular PDF should be downloaded from database. i have successfully done the uploading part. but when i try to download the file i got two type of problems.


<<download.php>>

<?php

$conn=odbc_connect('ex-policedsn','expolu','expolp');


$id = "my";
$query = "SELECT name, type, size, content " .
"FROM upload WHERE username = '$id'";

$result = odbc_do($conn,$query) or die('Error, query failed');
list($name, $type, $size, $content) = odbc_fetch_array($result);

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


exit;

?>

when user clicks the link it will call the download.php file. without downloading the PDF its just downloading blank download.php file. but the code works well in the local machine

could anyone help me please ????? :-(

Configuration: Windows XP
Chrome

Best answers for « Unable to download file from mysql database » in :
Backup/Restore Mysql database Show Backup/Restore Mysql database Backup Restore your database Note A simple approach on how to backup and restore MySQL databases. Backup To save an existing database it is recommended that you create a dump. To dump all...
MySQL real time monitoring ShowMySQL real time monitoring You are administrating a MySQL database and you want to analyze in real time the operations taking place in order to have a diagnostics over probable problems, errors or to monitor server activity. PhpMyAdmin...
.exe is not a valid Win32 application Show.exe is not a valid Win32 application Downloaded File IDE controller badly configured CD/DVD is unreadable File system corrupt File unregistered Virus/spyware Problem with browser configuration When you launch an executable file,...
MacOS X: Delete obstinate Files ShowMacOS X: Delete obstinate Files It may happens sometimes when trying to empty the recycle bin and that the files or folders you want to delete it still refuses to disappear. To resolve this problem, use a UNIX command in Terminal....
Download MYSQL to Access Database File Converter ShowTo handle Access database is more flexible than to handle MYSQL that is why it would be better to use this latter. To convert your database, Sanmaxi has edited a powerful tool to meet your needs. MYSQL to Access Database File Converter is a...
Download FileZilla Client ShowPossibilty to download a version compatible with Linux or MacOS FileZilla Client is a fast and reliable cross-platform FTP, FTPS and SFTP client with lots of useful features and an intuitive interface. Features : Easy to use ...
MS DOS Files and directories ShowFiles in MS DOS In a computers data is stored in files. When you run a program, MS-DOS processes the data stored in the file and passes it to the system. In MS-DOS a file can be any size, however the file name is more restricted, it can only have...
Operating Systems - MS-DOS - Tips ShowSetting the CD-ROM drive The CD-ROM drive is configured in the config.sys and autoexec.bat system files. The CD-ROM drive device driver must be configured in the config.sys file (even if the device is automatically detected in Windows). To do...

1

mikado33, on Jun 8, 2009 3:26:43 pm BST

Hye

all you have to do is to: set to TINYINT max value of 127 (NOOB!) change to INT

Thanks

Reply to mikado33

2

kuru, on Jun 9, 2009 2:12:35 am BST
  • +2

Thank you friend.

but i couldn't understand what you said.

this is my table structure

username varchar(30) PRIMARY KEY
name varchar(30)
type varchar(30)
size int(11)
content mediumblob

This is my requirement.

Admin will upload each client's agreement through website. which will be stored in the mysql database.

clients will login into the website and they can view a link "Download your agreement"

when client click the link it will call the "download.php" file. which should download the PDF file of the particular client from the database.

i was able to upload the file. but when i try to download the file through client login, its downloading the "download.php" (blank - no code inside) file.

why i'm getting this problem ???



<<download.php>>




<?php

$dbserver = "policedsn";
$uname = "exppo";
$pas = "exp";
$db = "polic";

mysql_connect("$dbserver","$uname","$pas") or die("Could not connect");
mysql_select_db("$db");


$id = "my"; // PDF file of username="my" should be downloaded now
$query = "SELECT name, type, size, content " .
"FROM upload WHERE username = '$id'";

$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);

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


exit;

?>





<<upload.php>>



$username=$_POST['client_username'];
$username = strtolower($username);




if($_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}



$conn=odbc_connect('server-name','username','password');



$query = "INSERT INTO upload (username,name, size, type, content ) ".
"VALUES ('$username', '$fileName', '$fileSize', '$fileType', '$content')";

$result = odbc_do($conn, $query);

odbc_close($conn);




Please Anybody help me out !!!!! :-(

Reply to kuru

3

 kuru, on Jun 9, 2009 8:09:21 am BST

:-)

i have solved the problem.

in the odbc_connect("","",""); statement

instead of giving the server name. i gave IP address. and it works fineeeeeeee...

kuru.

Reply to kuru