开发者

error in download a file from mysql

开发者 https://www.devze.com 2023-01-17 16:52 出处:网络
hello i have tryed a lot of source codes for this but i have the same error in all of them include \'functii.php\';

hello i have tryed a lot of source codes for this but i have the same error in all of them

include 'functii.php';
starts();
opendb();
$query = "SELECT content,`title_real`,`size`,`ext` FROM file WHERE file_id = '3'";

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

header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=$filename.$ext");
header("Content-Transfer-Encoding: binary");
hea开发者_开发知识库der("Content-Length: ".$size);

echo $content;

exit; 

the problem is that in the downloaded file i have a lot of "\0" that came from nowhere. the file is well stored in the database. i tested that. thank you


It sounds like an encoding issue. It could be that the file is encoded in UTF-16 and you are displaying it as if it were ASCII.


Try to:

header("Content-Disposition: attachment; filename = $filename . '.' . $ext");

instead of:

header("Content-Disposition: attachment; filename=$filename.$ext");


3 things :

  1. As Alexander.Plutov said, you got an error in the filename, it should be $filename.'.'.$ext You're missing the "." between the filename and its extension.
  2. As Mark Byers said, it may seem like an encoding issue, you should check your PHP file encoding as well as your DB's one.
  3. Hope you're only stocking text based file, because, any other file content definitely shouldn't be stored in a database! And even for text based file, it shouldn't be used for that, it's not its purpose at all.

In any other case than file generation, files should be stored in your server and may be called from your DB thanks to file path and name.

0

精彩评论

暂无评论...
验证码 换一张
取 消