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.

It’s set as part of the overall application settings under (left hand side) - Application | Settings | Maximum file size (right pane, settings section near the bottom)

Thanks!

Is the entry there referring to MB’s or Kilo-Bytes?

So if you enter 3 does that mean 3MB’s ?

Ok…now I’m confused?

I have set the Maximum File Size = 3 as described by “adz1111” above.

I assume that is in MB’s ?

Regardless of what I set it to it doesn’t seem to reject a image upload of 5.5MB that I’m testing with?

I thought the multi-upload would reject the the image if it was over the set 3MB limit ?

Can some one point me in the right direction here?

What am I doing wrong?

I read somewhere it’s bytes, but when I tested with just a “1”, it still uploads any size! Suspect this is a bug :frowning:

Anyone from Scriptcase support comment on this ?

Is this a bug?

Hello Everyone.

I’m hoping someone here can give the answer to this.

I’ve spent a ton of time with SC support and it must be a language barrier as I could never get the answers I required.

It seems that SC “Maximum File Size” - (Application, Settings) really doesn’t do anything according to support.

SC support is telling me that if I want to limit a file upload (3MB Max) through “Multi_upload” that I need to set my "php.ini - (upload_max_filesize = 3M).

I get what there saying but if you try it out it doesn’t work. If your try as an example to upload a 5MB image the progress bar will progress all the way to the end and just stop and nothing else happens?

I get why this happens as somewhere in the background PHP hangs because it doesn’t know what to do with the %MB file as its only allowing 3MB max.

Errors must be happening in the background but SC doesn’t handle them.

SC support says I need to implement extra code to catch the error and use “sc_message_error” to display an error to the user.

They suggested using the “onBeforeInsert” and “onBeforeUpdate” events.

That’s fine but they could not show me how to accomplish this.

Does anyone here show an example of how to do this?

[QUOTE=instore;25628]Hello Everyone.

I’m hoping someone here can give the answer to this.

I’ve spent a ton of time with SC support and it must be a language barrier as I could never get the answers I required.

It seems that SC “Maximum File Size” - (Application, Settings) really doesn’t do anything according to support.

SC support is telling me that if I want to limit a file upload (3MB Max) through “Multi_upload” that I need to set my "php.ini - (upload_max_filesize = 3M).

I get what there saying but if you try it out it doesn’t work. If your try as an example to upload a 5MB image the progress bar will progress all the way to the end and just stop and nothing else happens?

I get why this happens as somewhere in the background PHP hangs because it doesn’t know what to do with the %MB file as its only allowing 3MB max.

Errors must be happening in the background but SC doesn’t handle them.

SC support says I need to implement extra code to catch the error and use “sc_message_error” to display an error to the user.

They suggested using the “onBeforeInsert” and “onBeforeUpdate” events.

That’s fine but they could not show me how to accomplish this.

Does anyone here show an example of how to do this?[/QUOTE]

I’ve done it!!! (i guess)… you have to evaluate (in bits 1MB= 1024000) the size of the uploaded file. an example can be:

$Size=filesize($this->SC_IMG_FieldName)// note that $this->SC_IMG_ is PHP SC Code and fieldName is the name of an image field

then you have the way to evaluate file sizes… i hope to help with u

Thanks Welectronic !!

Can you show me a working example of what you did?

I would really appreciate it.

:slight_smile:

Anyone able to show a working example?

It would be a big help to alot of users.

:slight_smile:

Code to handle file size

I will try to do my best :confused:

  • First, create a field named [B]ImageField[/B], type Image(filename). No more configuration needed.
  • Second, in the onValidate event paste the next code:

$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

if (isset ($FieldName))
	{	
	 $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 help

This is great as a workaround - however, ideally, SC should fix the field where you specify a max filesize so that it actually works rather than that field currently being ignored for some reason!

Awesome welectronic but i’m using “image (Database)”.

Does that make a difference as I get the error “Undefined property: form_tb_byob_orders_collapse_apl::$SC_IMG_PP_images” when I click the save record button and it tries to validate?

Your help is appreciated!

Hello instore,

note that an image in a database field is not a file, it’s only a group of bytes that must be decoded, i suggest to refer this page to get the file size of a bolb field http://www.virendrachandak.com/techtalk/how-to-get-size-of-blob-in-mysql/.

SC doesn’t have support for file handling tooooo bad, but is a good tool for RAD.

hi welectronic, and thanks for this solution, it works with me on image (file name) as described

however, i have this field “Not Required” so if left empty it gives this error:

Undefined property: form_new_apl::$SC_IMG_ImageField

any idea!?

Mike

Hello,

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

You need to change the code as is shown next:

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

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

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

:slight_smile:

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!

I’ve done some changes because of the validation process:

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

this is the code i’m using rgt now:


/**************************************************************
*********** 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:


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!!

ScreenShot 2.jpg