WordPress.org

Ready to get started?Download WordPress

Forums

Media Upload - CATCH a Fatal error: Allowed memory size exhausted (1 post)

  1. matthias_123
    Member
    Posted 2 years ago #

    Hello !

    The Problem in short:
    Sometimes when I or a client uploads an image I get a
    Fatal error: Allowed memory size ... exhausted
    error due to the small memory_limit provided by the hoster.
    (the error could originate from media.php / line 258 - but thats just an example)

    Increasing the memory_limit is not an option (so no .htaccess, php.ini or any stuff like that)
    The only possible option (from my point of view) is catch the error
    (as it is an fatal error I might have to use register_shutdown_function) but I´d rather NOT mess with the core files of wordpress.

    Is there ANY way the wordpress cracks might suggest that could handle the given problem
    (I have already limited the maximum upload size of images with the following code - but this is of course no solution to the problem - it might just limit the number the fatal error is thrown)

    add_filter('wp_handle_upload_prefilter', 'limit_upload_max_image_size');
    function limit_upload_max_image_size($file) {
    	$max_image_upload_size = 1800 * 1024; // 1.8 MB
    	$is_image = false;
    	if (isset($file['tmp_name'])) {
    		$file_size = getimagesize($file['tmp_name']);
    		if (!isset($file_size['error'])) {
    			$is_image = $file_size['mime']; // image
    		}
    	}
    	if ($is_image && $file['size'] > $max_image_upload_size) {
    		$file['error'] = 'Maximum Image Upload Size is: '.($max_image_upload_size/1024).' KB';
    	}
    	return $file;
    }

    SO: howto catch a fatal error in wordpress ?

    thanks a lot - hope anyone can help me with this problem (cause - from a client perspective - it makes the system unreliable und probably even unuseable)

    thanks,
    matthias

Topic Closed

This topic has been closed to new replies.

About this Topic