gpt4 book ai didi

PHP PDF 使用 blob 数据动态压缩

转载 作者:行者123 更新时间:2023-12-04 05:41:02 25 4
gpt4 key购买 nike

我想使用下面的脚本将作为 blob 数据存储的 pdf 文件添加到 ZIP。

我收到两个我不明白的错误

Warning: file_put_contents(ATPstatement201203.pdf) [function.file-put-contents]: failed to open stream: Permission denied





Notice: ZipArchive::addFile() [ziparchive.addfile]: Empty string as filename



我不知道我做错了什么?
$TP_Month  =''.$_POST["tp_year"].''.$_POST["tp_month"].'';
$TP_format =$TP_Month;

echo $_POST["ids"];

$zip = new ZipArchive;
$zip->open('file.zip', ZipArchive::CREATE);
foreach( explode( ',', $_POST["ids"]) as $Client_ID)
{
$sql_qry="select *
from ca_client_statement
where client_id='".$Client_ID."' and trading_period_month like '".$TP_Month."'";
$sql_err_no=sql_select($sql_qry,$sql_res,$sql_row_count,$sql_err,$sql_uerr);

$row = mysql_fetch_assoc($sql_res);
$file_content = $row['pdf_statement'];
$file_name = ''.$Client_ID.'statement'.$TP_format.'.pdf';
$file=file_put_contents($file_name, $file_content);
$zip->addFile($file);
}
$zip->close();

header('Content-Type: application/zip');
header('Content-disposition: attachment; filename=filename.zip');
header('Content-Length: ' . filesize($zipfilename));
readfile($zipname);

最佳答案

“权限被拒绝”意味着 Web 服务器没有写入您尝试将文件保存到的位置的权限。您必须使用 chmod 更改您尝试写入的目录的权限。从命令行(如果您使用的是 linux)。

作为错误的证明,您可以执行 chmod 777 /path/to/your/save/location ,但是保持开放的权限不是一个好主意,您应该将其拨回 644或者。

你得到“空字符串作为文件名”,因为 file_get_contents()失败(出现上述错误),失败时返回 bool 值 false (根据 the docs ),这(显然)被解释为空字符串文件名。

关于PHP PDF 使用 blob 数据动态压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11246334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com