Announcement

Collapse
No announcement yet.

Multi Upload (Size Limit) ?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • instore
    started a topic Multi Upload (Size Limit) ?

    Multi Upload (Size Limit) ?

    Hello,

    Is there anyway to limit the size (in MB's) of uploaded images to store in the mysql database?

    Right now it seems like any size goes?

    Any help is appreciated.

    Thanks.

  • welectronic
    replied
    At last... what happened.. thread closed or still opened??

    Leave a comment:


  • welectronic
    replied
    SC uploads the file to a temp folder first, and save the name to "$this->SC_IMG_FieldName" (for images) or "$this->SC_DOC_FieldName" (for docs) var, as Giu says it only works if the file is uploaded before, but checking the file size before it be saved to the file folder, can work fine.

    by the other side, try to match the js code exposed previously with SC, can be a real headache
    Last edited by welectronic; 09-07-2014, 05:25 AM.

    Leave a comment:


  • Giu
    replied
    I didn't readed all the thread carefully sorry, but the only way to prevent to upload the file, is do it client side.

    PHP runs on server side, and to check the size, file must be uploaded first. Once uploaded, you can check, delete, modify and whatever you want on this file. The only way to prevents the file to start uploading to the server, is do the check of size on client side with JS

    Leave a comment:


  • MikeDE
    replied
    oh you confuse me more now, actually it was working when first the guy put for us the code, it was preventing ok, but i had the image field "not required" so i tried to define it as if empty or if !== null, also using isset but didn't work, so he changed the code and there i was lost

    Leave a comment:


  • Giu
    replied
    Originally posted by itsme3 View Post
    Thank you Giu, will try that to see if prevents upload size for one field, although I see it too much for one field limit the size of the uploaded image! looks scary

    thanks dude
    This will not prevent. PHP is server side, first must be uploaded, and once uploaded it can check the size. If you wants to check before upload, you must do it via JS. Something similar to this.
    http://stackoverflow.com/questions/3...ize-validation
    Code:
    <form action="upload" enctype="multipart/form-data" method="post">
    
        Upload image:
        <input id="image-file" type="file" name="file" />
        <input type="submit" value="Upload" />
    
        <script type="text/javascript">
            $('#image-file').bind('change', function() {
                alert('This file size is: ' + this.files[0].size/1024/1024 + "MB");
            });
        </script>
    
    </form>

    Leave a comment:


  • MikeDE
    replied
    Thank you Giu, will try that to see if prevents upload size for one field, although I see it too much for one field limit the size of the uploaded image! looks scary

    thanks dude

    Leave a comment:


  • Giu
    replied
    Code:
    function size($size,$filepath,$nomev)
    		{
    			if (isset ($filepath))
    			{	
    	 			$error_test    = filesize($filepath) > ($size*1000);    // Error test
    	 			$error_message = 'Size of File '.$NomEv.' myst be lower or equal to '.$size.'KB.'; // Error message
    
    	 			// Redirection
    	 			if ($error_test)
    	  			{
    	 				sc_error_message($error_message);
    
    	  			}
    			}
    
    		}
    Basically this function receives the max size (in KB), the filepath of the file, and a name. It checks if file is greater than the size passed as parameter, and if it is, throw an error.
    sc_error_message shows an error and cancel the operation of the event.

    Code:
    /**************************************************************
    *********** Size control of a file*****************
    ************ Event: onValidate just lowercase ***************
    ***************************************************************/
    $rutadoc = $this->Ini->path_doc."/R".[region]."/Acceso/".[radicadoacceso]."/TallerMto/";
    $rutaimg = $this->Ini->root .$this->Ini->path_imagens."/R".[region]."/Acceso/".[radicadoacceso]."/TallerMto/";
    
    
    if (isset($this->evformato))
    {
    	size(1024,$rutadoc.trim($this->evformato),'formato SC006');//
    }
    
    if (isset($this->evlistaasistencia))
    {
    	size(1024,$rutadoc.trim($this->evlistaasistencia),'lista de asistencia');//
    }
    
    if (isset($this->evfotosticker))
    {
    	size(1024,$rutaimg.trim($this->evfotosticker),'fotografia sticker');//
    }
    
    if (isset($this->evfotoaviso))
    {
    	size(1024,$rutaimg.trim($this->evfotoaviso),'fotografia aviso informativo');//
    }
    
    if (isset($this->evgarantiaprimernivel))
    {
    	size(1024,$rutadoc.trim($this->evgarantiaprimernivel),'formato garantia primer nivel');//
    }
    
    
    /**************************************************************
    *********************** Fin del evento ************************
    ***************************************************************/
    Here, it calls the previous function to check every file, and if some of them is greater than 1MB, save operation will not be executed. Third parameter, as I mentioned, it's just a string to show in error message, for this reason I didn't translated.

    Leave a comment:


  • Giu
    replied
    I was invoked?

    When will stay in front of a PC I will translate the Spanish words.

    Leave a comment:


  • MikeDE
    replied
    Thank you welectronic, i know you tried hard, thanks for your time

    will try to understand this and apply accordingly

    meanwhile, perhaps some Spanish guys add notes to make it more clear for everybody

    Giu!?

    Leave a comment:


  • welectronic
    replied
    I've done some changes because of the validation process:

    ScreenShot 2.jpg

    as u see in the image above it works for requiered and not requiered fields.

    this is the code i'm using rgt now:

    Code:
    /**************************************************************
    *********** Control de tamaņo de la evidencia *****************
    ************ Evento: onValidate solo minusculas ***************
    ***************************************************************/
    $rutadoc = $this->Ini->path_doc."/R".[region]."/Acceso/".[radicadoacceso]."/TallerMto/";
    $rutaimg = $this->Ini->root .$this->Ini->path_imagens."/R".[region]."/Acceso/".[radicadoacceso]."/TallerMto/";
    
    
    if (isset($this->evformato))
    {
    	peso(1024,$rutadoc.trim($this->evformato),'formato SC006');//
    }
    
    if (isset($this->evlistaasistencia))
    {
    	peso(1024,$rutadoc.trim($this->evlistaasistencia),'lista de asistencia');//
    }
    
    if (isset($this->evfotosticker))
    {
    	peso(1024,$rutaimg.trim($this->evfotosticker),'fotografia sticker');//
    }
    
    if (isset($this->evfotoaviso))
    {
    	peso(1024,$rutaimg.trim($this->evfotoaviso),'fotografia aviso informativo');//
    }
    
    if (isset($this->evgarantiaprimernivel))
    {
    	peso(1024,$rutadoc.trim($this->evgarantiaprimernivel),'formato garantia primer nivel');//
    }
    
    
    /**************************************************************
    *********************** Fin del evento ************************
    ***************************************************************/
    sorry 4 the spanish code but i don't have enough time, the path "/R".[region]."/Acceso/".[radicadoacceso]."/TallerMto/"; obeys to subfolder created dynamically as subfolder attribute (/R[region]/Acceso/[radicadoacceso]/TallerMto)

    posted next the function "peso" code:

    Code:
    function peso ($Tamano,$Evidencia,$NomEv)
    		{
    			if (isset ($Evidencia))
    			{	
    	 			$error_test    = filesize($Evidencia) > ($Tamano*1000);    // Error test
    	 			$error_message = 'El tamaņo de la evidencia '.$NomEv.' debe ser menor o igual a '.$Tamano.'KB.'; // Error message
    
    	 			// Redirection
    	 			if ($error_test)
    	  			{
    	 				sc_error_message($error_message);
    
    	  			}
    			}
    
    		}
    good look!!
    Last edited by welectronic; 09-03-2014, 04:16 AM.

    Leave a comment:


  • MikeDE
    replied
    hi welectronic,

    it is exactly as you provided, accepts the field if it is not required, but also allows all sizes to be uploaded! can anyone confirm if this code works for him regarding putting size for uploaded size for specefic fields? because for me it works, but then it checks the field all the time, i have this field "not required" so if left empty gives that error said before, and if put as given example it works.... then after your second fix, it doesn't throw an error if the field is not filled, but also doesn't prevent the maximum size!

    Leave a comment:


  • welectronic
    replied
    can you send more info about the code you are using?? maybe screenshoots also??


    Leave a comment:


  • MikeDE
    replied
    yes, that made me upload without need to fill the non-required field ok,

    but also accepts size more than 5 mb!! i put the size i put in the code is 2048 which is 2 mb

    Leave a comment:


  • welectronic
    replied
    Hello,

    This message is because tha object is not defined, in fact.


    You need to change the code as is shown next:

    Code:
    if (isset ($this->SC_IMG_ImageField))
    	{
              $Size=1024;//Size in KB
              $FieldName=$this->SC_IMG_ImageField;
              $NamF='uploaded file';// just for message error handling, usefull when u have many images in separated fields
      	  $error_test    = filesize($FieldName) > ($Size*1000);    // Error test
    	  $error_message = 'The size of '.$NamF.' must be less than '.$Size.'KB.'; // Error message
    
    	  // Redirection
    	  if ($error_test)
    	  {
    	 	sc_error_message($error_message);
    		sc_error_exit();// note that many procedures can be disabled using  the exit error procedure
    	  }
    	 }
    I hope it can be helpfull 4 u

    Leave a comment:

Working...
X