wordpress - PHP ZipArchive still remains the path to the file even if the file is added without path -


guys! saw lot of posts talking using ziparchive , how rid of path structure inside zip. so, here's code:

$zipname = $post->post_title.".zip"; $zip = new ziparchive; $zip->open($zipname, ziparchive::create);  foreach($gallery $img) {     $attachment = get_attached_file($img['id']);     $zip->addfile($attachment, pathinfo($attachment,pathinfo_basename)); } $zip->close();  header('content-type: application/zip'); header('content-disposition: attachment; filename='.$zipname); header('content-length: ' . filesize($zipname)); readfile($zipname); exit; 

the problem is, zip file contains image without path, f.e. /image.jpg , same image in multiple directories appears on server /path/to/the/file/image.jpg.

so, i'm not sure why happening. can on this?

looking @ documentation of addfile:

$zip->addfile($attachment, pathinfo($attachment,pathinfo_basename)); 

pathinfo($attachment,pathinfo_basename) returning "base name", file name (without path). second parameter name (with path) of file in zip.

if want keep complete path structure in zip, should remove parameter:

$zip->addfile($attachment) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -