我有一個帶複選框的html表單。有人選擇一個或多個複選框並點擊刪除按鈕,然後它將刪除數據庫中的文件引用,並將文件從Amazon S3中刪除。這是我用來查找所有複選框的代碼創建多個php陣列
$checkbox_select = JRequest::getVar('checkboxselect', '', 'POST'); //just a Joomla way of doing a $_POST with extra security
var_dump($checkbox_select); //this returns: array(2) { ["video_1.mp4"]=> string(2) "on" ["video_2.mp4"]=> string(2) "on" ["video_3.mp4"]=> string(2) "on"}
// Localize and sanitize each individual value
foreach (array_keys($checkbox_select) as $element) {
$deleteNames[] = $db->quote($element);
}
var_dump($deleteNames); //array(3) { [0]=> string(13) "'video_3.mp4'" [1]=> string(13) "'video_2.mp4'" [2]=> string(13) "'video_1.mp4'" }
我的問題是使用Amazon S3和多個文件刪除。我需要把S3缺失的格式是相當混亂:
$s3->delete_objects('mybucket', array(
'objects' => array(// accepts a *list* of one or more *hashes*
// a *hash* that contains a "key" key with a value, and maybe a "version_id" key with a value
array('key' => 'object (file) name'),
// a second hash representing a file
// a third hash representing a file
// and so on...
),
));
據我所知(從S3 delete_objects功能)最終關聯數組key
作爲實際鍵值。隨着最後var_dump
我有數組中的所有視頻的名字,現在我只需要到數組轉換成一堆陣列格式爲:
array ('key' => 'video_1.mp4'),
array ('key' => 'video_2.mp4'),
array ('key' => 'video_3.mp4'),
...and so on
如何創建這些陣列?我應該使用第一個var_dump還是第二個(他們都列出了視頻文件名)?提前致謝。