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 8465767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:08:37+00:00 2026-06-10T15:08:37+00:00

I have an issue with my php photo upload script. When I upload a

  • 0

I have an issue with my php photo upload script. When I upload a file that exceeds 2mb, it won’t show that error when I click upload..yet it’s there in my script..any idea why this is? For ex. I uploaded a .wma file and It was 2.38MB..that exceeds the limit..but yet it just says “file type not allowed” why didn’t it show the exceeds 2mb error as well?

Here is my script:

<?php
include 'init.php';

if(!logged_in()){
header('Location: index.php');
exit();
}

include 'template/header.php';
?>

<h3>Upload Image</h3>

<?php

if(isset($_FILES['image'], $_POST['album_id'])){
$image_name = $_FILES['image']['name'];
$image_size = $_FILES['image']['size'];
$image_temp = $_FILES['image']['tmp_name'];

$allowed_ext = array('jpg', 'jpeg', 'png', 'gif');
$image_ext = strtolower(end(explode('.', $image_name)));

$album_id = $_POST['album_id'];

$errors = array();

if (empty($image_name) || empty($album_id)){
    $errors[] = 'Something is missing';
} else {

    if(in_array($image_ext, $allowed_ext) === false){
        $errors[] = 'File type not allowed';
    }

    if($image_size > 2097152){
        $errors[] = 'Maximum file size is 2MB'; 
    }

    if(album_check($album_id) === false){
        $errors[] = 'Couldn\'t upload to that album';
    }

}

if(!empty($errors)){
    foreach ($errors as $error){
        echo $error, '<br />';
    }
} else {
    // upload image
}
}

$albums = get_albums();

if(empty($albums)){
echo '<p>You don\'t have any albums. <a href="create_album.php">Create an album</a></p>';
} else {
?>

<form action="" method="post" enctype="multipart/form-data">
<p>Choose a file:<br /><input type="file" name="image" /></p>
<p>
Choose an album:<br />
<select name="album_id">
    <?php 
    foreach ($albums as $album){
        echo '<option value="', $album['id'], '">', $album['name'], '</option>';
    }
    ?>
</select>
</p>
<p><input type="submit" value="Upload" /></p>
</form>

<?php
}

include 'template/footer.php';
?>

Thanks again for all of the patience with my probably easy posts for a lot of you more experienced programmers out there!
-TechGuy24

  • 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-06-10T15:08:39+00:00Added an answer on June 10, 2026 at 3:08 pm

    As per code, it should, if uploaded file size is >2mb. However, computers never make mistake but the human and thus debugging is important.

    Just replace the code

    if($image_size > 2097152){
        $errors[] = 'Maximum file size is 2MB'; 
    }
    

    with debug statements

    if($image_size > 2097152){
        echo "in if, image size=".$image_size;
        $errors[] = 'Maximum file size is 2MB'; 
    } else {
        echo "in else, image size=".$image_size;
    }
    

    This is just a first step of debugging. It may or may not fix the real cause. Let us know the output.

    Edit after comment:

    Put that code in the starting of the file.

    echo "files<pre>";
    print_r($_FILES);
    echo "</pre>imgsz=".$_FILES['image']['size'];
    

    What is the output. I guess it might include

    [error] => 1
    

    If it show error=1, Check http://php.net/manual/en/features.file-upload.errors.php

    That mean your upload_max_filesize in php.ini is set to 2MB or less. As soon as person upload file bigger than that, it never reach your code as PHP reject the file by default.

    To fix that, open php.ini and increase the limit of upload_max_filesize.

    Edit 3 after comment

    Change

    if($image_size > 2097152){
    

    to

    if($_FILES['image']['error']==1){
    

    That will fix the issue.

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

Sidebar

Related Questions

I have a simple XML extraction issue that should be solvable with straight PHP
I have some issues with a PHP file that is not working properly. The
I have had problems with a simple php script in which I can upload
I have an issue in writing fixed width text file using php and data
I have encounteed an issue with php treating 0 differently. I run following script
I have PHP issue, I'm trying to force a file download using php if
I have an issue with exporting BLOB to a csv file using php. Obviously
I have an issue in a PHP script which checks if the tax number
I have a while loop issue in PHP that seems like it could have
I have an issue about writing HTML file with PHP. I have this function

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.