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!?
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!?
I was invoked?
When will stay in front of a PC I will translate the Spanish words.
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.
/**************************************************************
*********** 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.
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
[QUOTE=itsme3;26806]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[/QUOTE]
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/3717793/javascript-file-upload-size-validation
<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>
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
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
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
At last… what happened… thread closed or still opened??