duanfu5239 2015-04-02 10:52
浏览 272
已采纳

php ziparchive重命名文件为空

I'm using php to create a ziparchive which contains some images. This works fine exept when i try to rename the files. This is the code that works:

$zip_archive->open(tempnam("tmp", "zip"), ZipArchive::OVERWRITE);
foreach ($images as $image) {
  $path = $image['path'];
  $title = $image['title'];
  if(file_exists($path)){
    $zip_file->addFile($path, pathinfo($path, PATHINFO_BASENAME));
  }
}
$zip_archive->close();

$images is an array and could look like this:

$images = array(
    'path' => array(
        'folder/title1.jpg',
        'folder/title2.jpg'
    ),
    'title' => array(
        'new_name1.jpg',
        'new_name2.jpg'
    )
)

I would like to name the image as its title.

$zip_file->addFile($path, $title);

But whats happening is that the files in the zip with the title as name are empty. What am I doing wrong?

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 ABAQUS简单的带传动系统运转不了
      • ¥15 关于git actions自动部署的问题
      • ¥25 小程序 view wx:for 循环太多时,如何在循环结束执行某个事件?
      • ¥15 曲率模态差matlab程序计算
      • ¥15 大概算是比较简单的坐标系旋转问题
      • ¥15 关于#python#的问题:安装完gym环境后
      • ¥15 关于稳像云台姿态控制中相机姿态误差表征
      • ¥15 求sm16306s驱动例程
      • ¥15 本地生活媒体平台口碑选品怎么获得权限
      • ¥15 R语言 回归树/袋装树/随机森林预测