Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1037903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:54:27+00:00 2026-05-16T14:54:27+00:00

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 12288 bytes).

  • 0

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 12288 bytes).

Thats the error i get when i try to upload a image on around 2,94 mb.

When i upload a image on 100kb and so it works fine. Why is this?

How can i make a restriction, so if you upload over xx bytes then you will get error that its too big, so i dont get that fatal error.

i started doing this at the form

$max_file_size = 8388608; 
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>">

Here’s my file upload:

<?php  
include "dbc.php";

$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);

$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'images/profilePhoto/';

$uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'editProfile.php';

$uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'home.php';

$fieldname = 'file';


// possible PHP upload errors
$errors = array(1 => 'php.ini max file size exceeded', 
                2 => 'html form max file size exceeded', 
                3 => 'file upload was only partial', 
                4 => 'no file was attached');

// check the upload form was actually submitted else print form
isset($_POST['submit'])
    or error('You need to upload a profilephoto, no?', $uploadForm);

// check for standard uploading errors
($_FILES[$fieldname]['error'] == 0)
    or error($errors[$_FILES[$fieldname]['error']], $uploadForm);

// check that the file we are working on really was an HTTP upload
@is_uploaded_file($_FILES[$fieldname]['tmp_name'])
    or error('not an HTTP upload', $uploadForm);

// validation... since this is an image upload script we 
// should run a check to make sure the upload is an image
@getimagesize($_FILES[$fieldname]['tmp_name'])
    or error('only image uploads are allowed', $uploadForm);

// make a unique filename for the uploaded file and check it is 
// not taken... if it is keep trying until we find a vacant one
$now = time();
while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
{
    $now++;
}

// now let's move the file to its final and allocate it with the new filename
makeThumbnail($_FILES[$fieldname],  122, 160, $v[id]); 
@move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
    or error('receiving directory insuffiecient permission', $uploadForm);
$filnamn =  $now.'-'.$_FILES[$fieldname]['name'];
    mysql_query("UPDATE users_profile SET photo = '$filnamn' WHERE uID = '$v[id]'") or die(mysql_error());
// If you got this far, everything has worked and the file has been successfully saved.
// We are now going to redirect the client to the success page.
echo "Du har nu bytt profillbild!";
// make an error handler which will be used if the upload fails
function error($error, $location, $seconds = 5)
{
    header("Refresh: $seconds; URL=\"$location\"");
    echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n".
    '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n".
    '<html lang="en">'."\n".
    '   <head>'."\n".
    '       <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n".
    '       <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n".
    '   <title>Upload error</title>'."\n\n".
    '   </head>'."\n\n".
    '   <body>'."\n\n".
    '   <div id="Upload">'."\n\n".
    '       <h1>Upload failure</h1>'."\n\n".
    '       <p>An error has occured: '."\n\n".
    '       <span class="red">' . $error . '...</span>'."\n\n".
    '       The upload form is reloading</p>'."\n\n".
    '    </div>'."\n\n".
    '</html>';
    exit;
} // end error handler
?>

MakeThumbnail function()

function makeThumbnail($file, $thumbSizeWidth, $thumbSizeHeight, $user) {
    if ($file['error'] !== UPLOAD_ERR_OK) {

        // something blew up
        // so handle error condition
        // 
        // error codes documentation: http://php.net/manual/en/features.file-upload.errors.php
        die();
    }

    $path_thumbs = "images/profilePhoto/thumbs/";
    $allowed_types = array('image/jpeg', 'image/jpg', 'image/bmp', 'image/png', 'image/gif');

    $imageinfo = getimagesize($file['tmp_name']); // get image info
list($width, $height, $type, $attr) = $imageinfo;

    if ($imageinfo === FALSE) {
        die("Uhoh. Unable to read uploaded file");
    }

    if (!in_array($imageinfo['mime'], $allowed_types)) {
        die("Sorry, images of type {$imageinfo['mime']} not allowed");
    }

    $rand_name = rand(0, 999999999); // this isn't particularly well done, but ...

    // create thumbnail
    switch($imageinfo['mime']) {
        case 'image/jpeg':
        case 'image/jpg':
            $new_img = imagecreatefromjpeg($file['tmp_name']);
            $file_ext = '.jpg';
            break;
        case 'image/gif':
            $new_img = imagecreatefromgif($file['tmp_name']);
            $file_ext = '.gif';
            break;
        case 'image/png':
            $new_img = imagecreatefrompng($file['tmp_name']);
            $file_ext = '.png';
            break;
        default:
            die("Uhoh. How did we get here? Unsupported image type");
    }

    $imgratio = $height / $width;


        $newwidth = $thumbSizeWidth;
        $newheight = $thumbSizeHeight;

    $resized_img = imagecreatetruecolor($newwidth, $newheight);
    imagecopyresampled($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

    $thumb_name = $rand_name . $file_ext;
    $thumb_path = $path_thumbs . '/' . $rand_name . $file_ext;
    imagejpeg($resized_img, $thumb_path);

mysql_query("UPDATE users_profile SET photo_thumb = '$thumb_name' WHERE uID = '$user'") or die(mysql_error());

    imagedestroy($resized_img);
    imagedestroy($new_img);

    return($thumb_name);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:54:27+00:00Added an answer on May 16, 2026 at 2:54 pm

    It sounds like it’s the overall memory_limit, not the upload limit. Are you processing the image once uploaded with GD?

    If so, this will be much more memory intensive on larger images if you’re doing a lot of post processing on the uploads – in this case try upping the memory limit, if you’re doing something much more straight forward then there is probably another cause for the large memory usage…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 136753 bytes)
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 40000 bytes)
Fatal error: Allowed memory size of 31457280 bytes exhausted (tried to allocate 9828 bytes).
I get the following compilation error fatal error C1189: #error : ERROR: Use of
Error message: fatal: git checkout: updating paths is incompatible with switching branches/forcing How to
I am getting the error OperationalError: FATAL: sorry, too many clients already when using
The log levels WARN, ERROR and FATAL are pretty clear. But when is something
The code below is resulting in an error on a site in which there
I'm using a code which will upload an image, put the image in the
I'm creating thumbnails cycling through a lot of images, when I find a large

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.