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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:50:50+00:00 2026-05-21T08:50:50+00:00

I have a simple file uploader, which thanks to stackoverflow is now fully working,

  • 0

I have a simple file uploader, which thanks to stackoverflow is now fully working, however when I copied the PHP code across to my main layout, once initialised to upload a file, but it is wrong format or size and it echos the error, it breaks the HTML below it. Im thinking its to do with the “exit;” after each echo? but could be wrong.

<?php
if($_POST['upload']) {
if($_FILES['image']['name'] == "")
{
    #there's no file name return an error
    echo "<br/><b>Please select a file to upload!\n</b>";
    exit;
}
#we have a filename, continue

#directory to upload to
$uploads = '/home/habbonow/public_html/other/quacked/photos';
$usruploads = 'photos';

#allowed file types
$type_array = array(image_type_to_mime_type(IMAGETYPE_JPEG), image_type_to_mime_type(IMAGETYPE_GIF), image_type_to_mime_type(IMAGETYPE_PNG), 'image/pjpeg');

if(!in_array($_FILES['image']['type'], $type_array))
{
    #the type of the file is not in the list we want to allow
    echo "<br/><b>That file type is not allowed!\n</b>";
    exit;
}

$max_filesize = 512000;
$max_filesize_kb = ($max_filesize / 1024);

if($_FILES['image']['size'] > $max_filesize)
{
    #file is larger than the value of $max_filesize return an error
    echo "<br/><b>Your file is too large, files may be up to ".$max_filesize_kb."kb\n</b>";
    exit;
}

$imagesize = getimagesize($_FILES['image']['tmp_name']);

#get width
$imagewidth = $imagesize[0];
#get height
$imageheight = $imagesize[1];

#allowed dimensions
$maxwidth = 1024;
$maxheight = 1024;

if($imagewidth > $maxwidth || $imageheight > $maxheight)
{
    #one or both of the image dimensions are larger than the allowed sizes return an error
    echo "<br/><b>Your file is too large, files may be up to ".$maxwidth."px x ".$maxheight."px in size\n</b>";
    exit;
}

move_uploaded_file($_FILES['image']['tmp_name'], $uploads.'/'.$_FILES['image']['name']) or die ("Couldn't upload ".$_FILES['image']['name']." \n");

echo "<br/>The URL to your photo is <b>" . $usruploads . "/" . $_FILES['image']['name'] . "</b>. Please use this when defining the gallery photos";

}

?>

<form name="uploader" method="post" action="" enctype="multipart/form-data">
      <input type="file" name="image" style="width:300px;cursor:pointer" />
      <input type="submit" name="upload" value="Upload Image" />
</form>
  • 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-21T08:50:50+00:00Added an answer on May 21, 2026 at 8:50 am

    Indeed, when you call exit; it means “immediately stop all processing; this script is finished.” Anything that comes after it — including HTML — will not be interpreted.

    A better organization would be to make this code a function, to the effect of:

    function uploadMyStuffPlease() {
    
        if($_POST['upload']) {
            if($_FILES['image']['name'] == "")
            {
                #there's no file name return an error
                echo "<br/><b>Please select a file to upload!\n</b>";
                return;
            }
            #we have a filename, continue
    
        // ....
    
    }
    

    Now you can simply call uploadMyStuffPlease(), which will do as much processing as it can, and perhaps return early in the event of an error. Either way, the function will return, and so the rest of your script (including that HTML) can still be interpreted.

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

Sidebar

Related Questions

I have a simple NAnt build file, which attempts to perform an update from
I have a very simple file upload PHP script. I am testing with a
I have a very simple photo uploader which needs some bringing up to speed
We have a simple file browser on our intranet, built using ASP/vbscript. The files
I have implemented a simple file upload-download mechanism. When a user clicks a file
I have a simple WPF (XAML) file that has some animated shapes and text.
I am implementing a very simple file database. I have 2 basic operations: void
I have a problem with a simple included file. The file being included is
I have a simple report that I want to export to a CSV file.
K... I'm doing something obviously wrong. I have a simple page with a file

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.