Próbuję utworzyć plik zip z załączników post w wordpress.PHP utworzyć plik zip (z wordpress załączników)
Próbowałem obu metod poniżej - ale wynika to w niczym (Brak komunikatów o błędach, nie utworzony plik) - Co robię źle (znowu ..)
nie sądzę, że fakt, że ci, są załącznikami post w wordpress ma coś z tym zrobić - ponieważ metody te zawiodły również normalnych plików. czemu ?
-> Zobacz odpowiedź.
$files_to_zip = array();// create files array
//run a query
$post_id = get_the_id();
$args = array(
'post_type' => 'attachment',
'numberposts' => null,
'post_status' => null,
'post_parent' => $post_id
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
$files_to_zip [] = wp_get_attachment_url($attachment->ID); // populate files array
}
}
print_r($files_to_zip);
$zip = new ZipArchive;
$zip->open('file.zip', ZipArchive::CREATE);
foreach ($files_to_zip as $file) {
$zip->addFile($file);
}
$zip->close();
i również ta metoda:
$files_to_zip = array(); // create array
//run a query
$post_id = get_the_id();
$args = array(
'post_type' => 'attachment',
'numberposts' => null,
'post_status' => null,
'post_parent' => $post_id
);
$zip = new ZipArchive;
$zip->open('file.zip', ZipArchive::CREATE);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
$zip->addFile(wp_get_attachment_url($attachment->ID));
}
}
print_r($files_to_zip);// debug - return file names OK
$zip->close();
Obie metody powrócił nic .. Wszelkie spostrzeżenia zostaną docenione.
EDIT I - próbka print_r do tablicy $ files_to_zip
print_r($files_to_zip);
Array (
[0] => http://localhost/testing_evn/wp-content/uploads/2012/03/wrt-62316IMAG0659.jpg
[2] => http://localhost/testing_evn/wp-content/uploads/2012/03/wrt-85520_IGP0255.jpg
[3] => http://localhost/testing_evn/wp-content/uploads/2012/03/wrt-85520_IZTP0635.jpg
[4] => http://localhost/testing_evn/wp-content/uploads/2012/03/wrt-85520_ITG035t5.jpg
[5] => http://localhost/testing_evn/wp-content/uploads/2012/03/wrt-85520_IRTT7375.jpg)
..by użyciu get_attached_file() będzie produkować prawdziwe ścieżkę (w pewnym momencie podejrzewałem, że może php nie można utworzyć na zamek HTTP. - i jest to krótka odpowiedź Patrz długiej jedną poniżej)
Nie ma natywnej funkcji PHP o nazwie 'create_zip()' - wyświetl kod dla tej funkcji. Pokaż także wynik 'var_dump ($ files_to_zip)' – DaveRandom
Zobacz moją edycję przykładowej tablicy. –