如何限制用户只上传3张图片?

时间:2015-04-13 11:39:06

标签: php jquery codeigniter gdlib

我在Codeigniter中创建了一个Web应用程序。这是VIEW中的代码。

<div class="bold light-gray">Add a photo or two!</div>
<p class="short">Or three, or more! Prospective Buyers love photos that highlight the features of your parts or gear.</p>
<form class="ajaxform" method="post" enctype="multipart/form-data" action='<?php echo site_url('UploadImage/upload_Image');?>'>
<input type="hidden" name="do" value="upload"/>
Upload your image <input type="file" name="Filedata" id="photo" onChange="abc()" />
<input type="hidden" name="timestamp" value="<?php echo $timestamp;?>" />
<input type="hidden" name="token" value="<?php echo md5('unique_salt' . $timestamp);?>" />
<input type="hidden" name="customer_id" value="<?php echo $customer['id'];?>" />
</form>
</div>
<!-- /.box.center -->
<?php echo form_open('/secure/add_item/'.$id, array('id'=>'listitem') ); ?>
<div id="img_cant"> <?php  
if(isset($images) && !empty($images)) {
foreach($images as $key=>$img){
 ?>
 <input type="hidden" value="<?php echo $img; ?>" name="images[]" id="hid_<?php echo $key; ?>">
 <?php 
}
} 
?>
</div>

我想让用户最多只添加3或4张图片。怎么做?

1 个答案:

答案 0 :(得分:0)

<?php $count=count($_FILES['name']);
if($count>3)
{
echo "Your error message";
}
else{
echo "your desired activity";
}?>