我有一个带有复选框的 html 表单。有人选择一个或多个复选框并点击删除按钮,然后它将从数据库中删除文件引用并从 Amazon S3 中删除文件。这是我用来查找所有复选框的代码
$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 还是第二个(它们都列出了视频文件名)?提前致谢。