这是我的代码:
HTML (多次上传):
<input type="file" name="attached_photo_1" id="attached_photo_1" />
<input type="file" name="attached_photo_2" id="attached_photo_2" />
<input type="file" name="attached_photo_3" id="attached_photo_3" />
<input type="file" name="attached_photo_4" id="attached_photo_4" />
<input type="file" name="attached_photo_5" id="attached_photo_5" />
.PHP
$photo_array = array(
$_FILES['attached_photo_1'],
$_FILES['attached_photo_2'],
$_FILES['attached_photo_3'],
$_FILES['attached_photo_4'],
$_FILES['attached_photo_5']
);
例
现在假设有人只上传了照片 1 和 2 的图像,留下了图像 3、4 和 5,错误代码为 4 美元_FILES(意味着没有上传文件)。
示例输出(使用 <?php print_r($photo_array); ?>
):
Array
(
[0] => Array
(
[name] => test.png
[type] => image/png
[tmp_name] => /Applications/XAMPP/xamppfiles/temp/php0JwXJc
[error] => 0
[size] => 3469655
)
[1] => Array
(
[name] => test-2.jpg
[type] => image/jpeg
[tmp_name] => /Applications/XAMPP/xamppfiles/temp/phpv7qFc6
[error] => 0
[size] => 1666451
)
[2] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)
[3] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)
[4] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)
)
主要问题:
如何删除子数组[error] => 4
的所有父数组元素? 因此,在上面的示例中,元素 [2]、[3] 和 [4] 将从数组中删除或取消设置。
至少试一试。请参阅以下伪代码,了解如何实现此目的。
foreach($photo_array as $key => $values){
if(isset($key['name']))
$photo_array[$key] = $values;
}
}