如何将变量放入数组?

时间:2016-04-26 01:56:36

标签: php arrays compression

我试图将变量放在数组$ filename中。 以下代码正在运行:

$files = array('http://xyz.xyz/subtitle/contributor/subtitle/file/The.Bourne.Legacy.2012.All.BluRayRip.1080p.720p.and.Ganool.sebuah-dongeng.blogspot.com.srt');

但是,我想把变量$ data [' zipname']放在数组$ files中 这样变量就会根据DB的数据而改变。

到目前为止,压缩工作正在进行,但我无法找到如何使阵列获得正确的链接。

$files = array('http://xyz.xyz/contributor/sub/file/".$data['zipname']."');

$zip = new ZipArchive();
$tmp_file = tempnam('temp','');

$zip->open($tmp_file, ZipArchive::CREATE);

foreach($files as $file){
    $download_file = file_get_contents($file);
    $zip->addFromString(basename($file),$download_file);
}

$zip->close();

header('Content-disposition: attachment; filename=download.zip');
header('Content-type: application/zip');
readfile($tmp_file);

2 个答案:

答案 0 :(得分:1)

如果不需要双引号$files = array('http://xyz.xyz/contributor/sub/file/"' . $data['zipname'] . '"' );

{{1}}

如果需要:

{{1}}

答案 1 :(得分:0)

  

如何将变量放入数组

$data['zipname']内使用双引号花括号展开变量array,即:

$files = array("http://xyz.xyz/contributor/sub/file/{$data['zipname']}");
相关问题