0
我最近發現PHP的ZipArchive,我沒有任何問題,從字符串中添加文件或文件,但我有一個圖像blob內MySQL數據庫,我想添加到ZipArchive。我可以在一個單獨的文件中獲取圖像,我也可以將它作爲jpg下載。我希望能夠將圖像添加到存檔中。從mysql blob數據庫中添加一個圖像ZipArchive
下面的代碼顯示瞭如何訪問我的BLOB
header('Content-Type: image/jpg; charset=utf-8');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
$conB = mysql_connect("localhost", "user_name", "user_pass");//connect to the database
if (!$conB)
{
die('Could not connect: ' . mysql_error()); // if cannot connect then send error message
}
mysql_select_db("binary", $conB); // define database name
$id = $_GET['ids'];
$query = mysql_query("SELECT * FROM tbl_images WHERE ID ='".$id."' ");
while($row = mysql_fetch_array($query))
{
$content = $row['image'];
header('Content-Disposition: attachment; filename=image"'.$row['ID'].'".jpg');
fwrite($output, $content);
}
這一切對我來說工作正常,下面的代碼演示瞭如何我將文件添加到一個zip壓縮文件
$zip = new ZipArchive();
$ZipFileName = "newZipFile.zip";
if ($zip->open($ZipFileName, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true)
{
echo "Cannot Open for writing";
}
$zip->addEmptyDir('newFolder');
$zip->addFromString('text.txt', 'text file');
$zip->close();
//then send the headers to foce download the zip file
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$ZipFileName");
header("Pragma: no-cache");
header("Expires: 0");
readfile($ZipFileName);
是否有一個人知道我可以如何一起實施它們?
如果您需要任何更多信息的話,我可以提供它:)
輝煌的工作治療,我想我嘗試了其他組合:) – Martin
@Martin歡迎您 – DevZer0