hello ,
this is praveen.i am new to this forum
I had one problem while downloading images,pdf or compressed files from mysql databse. It shows unknown format(as a corrupted file) while downloading files from database.
below was my table structure
CREATE TABLE upload_download (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
type VARCHAR(50) NOT NULL,
size INT NOT NULL,
content MEDIUMBLOB NOT NULL,
PRIMARY KEY(id)
);
below was the script for uploading files
<?php
include 'functions.inc';
$links = "<A HREF='upload.html'>Click here to proceed to the upload page</A>";
if(isset($_POST['upload']) && $_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);
}
Connect_mysqldb();
$query = "INSERT INTO upload_download(name, size, type, content ) VALUES('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
echo "<br>File $fileName uploaded<br>";
echo '"<a href="upload.html">click here to go back to upload page </a>"';
}else{
echo "please select the file to download <br /> ";
echo $links;
}
?>
below was the script for downloading files
<?php
require "functions.inc";
// if id is set then get the file with the id from database
$downloadid = $_GET['id'];
connect_mysqldb();
echo $id;
$query = "SELECT name, type, size, content FROM upload_download WHERE id = '".$id."' ";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);
header("Content-type: $type");
header("Content-Length: $size");
header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename=$name');
header("Content-Transfer-Encoding: binary\n");
header("Content-Disposition: attachment; filename=$name");
echo $content;
exit;
?>
is there any modification needed in script.?
if u have any script send to this mail
praveen8632@gmail.com
waiting fro ur reply.thanks in advance