0

I can check a simple variable if it's empty or not. But how do i check the array value which is come from Html Upload Form. Like: name=images[];

Simple variable check:

if(empty($somevalue))
  $err[] = "your variable is empty";

But how do i check if it's something like this:

<input name="images[]" type="file"/>

Update Code:

<?php
if(isset($_POST['Submit']) && $_POST['Submit'] == "Save & Continue")
{
$number_of_file_fields = 0;
$number_of_uploaded_files = 0;
$number_of_moved_files = 0;
$uploaded_files = array();
$upload_directory = dirname(__file__) . '/uploaded/'; //set upload directory

$img[] = $_FILES['images']['name']; 
$img = array();
$err = array();

if(isset($img))
{
    if(empty($img)) 
        $err[] = "Your property picture require";           
}

if(!empty($err))
{
    foreach($err as $er)
    {
        echo $er;
    }   
}
else
{
    echo "done";    
}

}

?>
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data"   
name="mutiple_file_upload_form" id="mutiple_file_upload_form">
<table width="1020" border="0" cellspacing="7" cellpadding="0">   
 <tr>
 <td valign="top" width="250">
     Upload your property pictures
     </td>
     <td>
      <div id="file_container">
        <input name="images[]" type="file" class="tr2"  />
        <br />
      </div>
      <a href="javascript:void(0);" onClick="add_file_field();">Add another</a><br />
      <input type="submit" value="Save & Continue" name="Submit" class="submit" />
      </td>
 </tr> 
 </table>
</form> 
</table>  
4

2 回答 2

0

您仍然可以empty()在阵列上使用。

文档

以下内容被认为是空的:

...
array() (一个空数组)
...

但是,您应该注意,这empty()将返回一个包含元素false的数组。看看你是否需要考虑这个。array_filter()

于 2012-11-19T16:13:02.883 回答
0

您只需忽略 PHP 端的方形背衬

if empty($_POST['images'])

于 2012-11-19T16:14:44.157 回答