This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 2

File size error message?


  1. NLA
    Member

    I searched forum and found fix to limit file types in config.php. I'm now looking for fix for max file size. I tried several of the answers and was only able to get it to work by creating a php.ini file, and then uploading it to the root of install. The file contains the following:

    -----------

    php.ini file:
    post_max_size = 100000
    upload_max_filesize = 100000

    settings.php:
    ini_set('post_max_size', '100000');
    ini_set('upload_max_filesize', '100000');

    -----------

    It stops larger files from uploading, but no error message is displayed like when wrong file type is used. It just returns user back to the form with uploads field blank. I don't have access to php.ini on server, and that is why I created one to put in Machform directory.

    Any ideas on how to return an error message to the user within the form?

    Otherwise the software works great and I am glad I found your site. Thanks.

    Posted 15 years ago #
  2. redityo

    Hi,

    You can add another validation by editing some files, but you still need to set "post_max_size" value.
    First Edit your "includes/common-validator.php" and add these code around line 29 :

    //validation for required file
    	function validate_max_file($value){
    		$error_message = "You can not upload more that 2 Kb";
    		$element_file = $value[0];
    
    		if($_FILES[$element_file]['size'] < 2000){
    			return true;
    		}else{
    			return $error_message;
    		}
    	}

    after that, edit your "includes/post-function.php" and search around line 804, you will see these code :

    $rules[$element_name]['filetype'] 	= true;

    exactly below that code , add this code :

    $rules[$element_name]['max_file'] 	= true;

    MachForm Support

    Posted 15 years ago #
  3. NLA
    Member

    Thank you very much. That worked great.

    Posted 15 years ago #
  4. Jackson
    Member

    May I ask where to find the settings.php so that I can insert the two lines of code?
    ini_set('post_max_size', '100000');
    ini_set('upload_max_filesize', '100000');

    Posted 15 years ago #
  5. redityo

    Hmmm .. you should put those code in "config.php" file


    MachForm Support

    Posted 15 years ago #
  6. Jackson
    Member

    I must be missing something... what I've done is:

    - insert into config.php
    ini_set('post_max_size', '100000');
    ini_set('upload_max_filesize', '100000');

    - insert into php.ini
    post_max_size = 100000
    upload_max_filesize = 100000

    - edit the includes/common-validator
    inserted the above code

    - edit includes/post-function.php
    inserted the above code

    Yes the php.ini stops any files larger than 100kb from uploading, but still no error message.

    Posted 15 years ago #
  7. Jackson
    Member

    I figure it out at last.... I should NOT set the post_max_size in php.ini

    Just modify the config.php, common-validator.php, and post-function.php

    Thank you so much.

    Posted 15 years ago #

RSS feed for this topic

Reply