मैं वर्डप्रेस में पोस्ट अटैचमेंट से ज़िप फ़ाइल बनाने की कोशिश कर रहा हूं।PHP ज़िप फ़ाइल (पोस्ट अनुलग्नक वर्डप्रेस से)
मैं दोनों तरीकों से नीचे की कोशिश की है - लेकिन यह कुछ भी नहीं में परिणाम (कोई त्रुटि संदेश, कोई फ़ाइल बनाई) - क्या मुझे नहीं लगता कि तथ्य यह है कि उन है कर रहा हूँ मैं गलत कर (फिर से ..)
वर्डप्रेस में पोस्ट अनुलग्नक हैं इसके साथ कुछ भी करना है - क्योंकि वे विधियां सामान्य फ़ाइलों के साथ भी विफल रही हैं। क्यूं कर ?
-> उत्तर देखें।
$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();
है और यह भी इस विधि:
$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();
दोनों ही तरीकों से कुछ भी नहीं लौटे .. किसी भी अंतर्दृष्टि की सराहना की जाएगी।
संपादित मैं - सरणी $ 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)
get_attached_file() यह असली पथ का उत्पादन करेगा का उपयोग कर ..by के लिए नमूना print_r (कुछ बिंदु पर मैं शक था कि हो सकता है php जिप से अधिक नहीं बना सकते HTTP -। और उस संक्षिप्त उत्तर है नीचे लंबे एक देखें)
कोई create PHP फ़ंक्शन नहीं है जिसे 'create_zip()' कहा जाता है - कृपया इस फ़ंक्शन के लिए कोड दिखाएं। साथ ही, कृपया 'var_dump ($ files_to_zip)' – DaveRandom
का परिणाम दिखाएं नमूना सरणी के लिए मेरा संपादन देखें। –