簡體   English   中英

如何限制用戶僅上傳3張圖片?

[英]How to restrict user to Upload only 3 images?

我正在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張圖像。 怎么做?

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

使用jquery,您可以在提交表單時調用此函數

var file_nu = $("input:file")[0].files.length;
if(file_nu >3)//apply your condition here
{
 return FALSE;
}else{
 return TRUE;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM