Set Maximum File Limit

Last post 04-09-2012, 5:31 AM by sonirachna. 2 replies.
Sort Posts: Previous Next
  •  04-09-2012, 2:08 AM 73662

    Set Maximum File Limit

    Hi, How do i set maximum file limit from text field.

    I have a form  field name "No Of Spread". Uploader will allow files according to that text filed . See my code below:

    <tr >
          <td colspan="2" >Number of Spreads <span > * </span></td>
        </tr>
        <tr >
          <td colspan="2" ><input  type="text" name="no_of_spreads" id="no_of_spreads" class="EFU_num_req" onblur="BLOCKED SCRIPTCheckSpreads(this.value);"/>
             </td>
        </tr>
        
        <tr >
          <td colspan="2" >Select Spreads <span > * </span></td>
        </tr>
        
        <tr >
          <td colspan="2" ><!--<input id="my_file_element" class="EFU_file_req" type="file" name="file_1" >-->
          
          <?php
                $uploader=new PhpUploader();
                
                $uploader->MultipleFilesUpload=true;
                $uploader->InsertText="Upload Multiple File";
                $uploader->SaveDirectory= plugin_dir_path(__FILE__)."/savefiles";
                $uploader->MaxSizeKB=1024000;    
                $uploader->MaxFilesLimit= '<script language="javascript">
          document.getElementById("no_of_spreads").value();
          </script>';
                //$uploader->UploadUrl="demo2_upload.php";
                $uploader->Name="myuploader";
                $uploader->ManualStartUpload=true;
                $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif,*.bmp,*.png,*.jpeg,*.zip,*.rar";
                
                //Where'd the files go?
                //$uploader->SaveDirectory="/myfolder";
                
                $uploader->Render();
            ?>


    Please Suggest
  •  04-09-2012, 4:11 AM 73665 in reply to 73662

    Re: Set Maximum File Limit

    Hi,
     
    If you want to set the limitation by the input value, I suggest you try function "CuteWebUI_AjaxUploader_OnSelect", like the example below.
     
    MaxFilesLimit is the server side property, can not set by the javascript code.
    1. <?php require_once "phpuploader/include_phpuploader.php" ?>  
    2. <?php session_start(); ?>  
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
    4. <html xmlns="http://www.w3.org/1999/xhtml">  
    5. <head>  
    6.     <title>example</title>  
    7. </head>  
    8. <body>  
    9. <div>  
    10.   <input onkeyup="value=value.replace(/[^\d]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"  
    11.             id="no_of_spreads" >  
    12.   
    13.     <?php  
    14.         $uploader=new PhpUploader();  
    15.         $uploader->MultipleFilesUpload=true;  
    16.         $uploader->InsertText="Select multiple files (Max 10M)";  
    17.         $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif,*.bmp";  
    18.         $uploader->Render();  
    19.     ?>  
    20.       
    21.     <script type='text/javascript'>  
    22.     var no_of_spreads= document.getElementById("no_of_spreads");  
    23.     function CuteWebUI_AjaxUploader_OnSelect(files)  
    24.     {  
    25.         if(no_of_spreads.value=="")  
    26.         {  
    27.             alert("The maximun number of files allowed to be uploaded is set to 0");  
    28.             return false;  
    29.         }  
    30.         if(files.length>no_of_spreads.value)  
    31.         {  
    32.             alert("The maximun number of files allowed to be uploaded is set to "+no_of_spreads.value);  
    33.             return false;  
    34.         }  
    35.     }  
    36.     </script>  
    37.     </div>  
    38. </body>  
    39.       
    40. </html>  
    Regards,
     
    Ken 
  •  04-09-2012, 5:31 AM 73669 in reply to 73665

    Re: Set Maximum File Limit

    Thanks Ken.

    Its working now.
     
    Thanks a lot.
View as RSS news feed in XML