vendredi 30 janvier 2015

Arrays - Multiple Files Upload - Delete Parent Array Element Where Child Array ['error'] => 4

Here is my code:


HTML (Multiple Uploads):



<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']
);


Example


Now lets say someone only uploaded images for photo 1 and 2, leaving images 3, 4, and 5 with a $_FILES error code of 4 (meaning no file was uploaded).


Example Output (using <?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
)

)




MAIN QUESTION:

How Can I remove all of the parent array elements where the child array's [error] => 4? Thus in the example above elements [2], [3], and [4] would be deleted or unset from the array.


Aucun commentaire:

Enregistrer un commentaire