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

  • SEARCH
  • Home
  • 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 9277293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:04:25+00:00 2026-06-18T17:04:25+00:00

enter code here This is my first post on Stack Overflow, so please forgive

  • 0

enter code hereThis is my first post on Stack Overflow, so please forgive me if I am too vague and do not give you the necessary information to diagnose my problem right away!

I have created a temporary page that uses a form to upload an image. The form then posts to a php page that resamples the image and creates a new image, resized and cropped.

The problem I have is that on the php page that the image uploads to, all of the PHP code posts properly and functions as I expect it to, BUT all of the HTML code displays in the browser without formatting. I am not sure why, I have never come into this problem before.

Here is the code for the upload form page:

<! Image test: Testing the ability to upload an image, resize and crop. >
<! Idealy, this procedure would be performed on large images. >

<! Car Listing page images: 280 x 200 px >

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   <?php require_once("baseopen.php"); ?>
   <?php

   if (isset($_POST['error1'])) {
    $error = "The file selected was not of the correct filetype.<br />
     Please select a different file to upload.";
   }

   ?>

   <html>
   <?php if (isset($error)) { echo $error; } ?>
   <p>Select an image of type <b>.JPG, .GIF, .PNG, or .BMP</b> to upload.</p><br />
   <form action="converter.php" method="post" enctype="multipart/form-data">
   <label for="image">Picture:</label>
   <input type="file" name="image"><br />
   <input type="submit" name="submit" value="Upload">
   </form>

   </html>

   <?php mysql_close($data); ?>

Here is what I have for the processing PHP that is giving me the problem and outputting all the HTML tags. (Please note, the PHP IS processed and NOT displayed in the browser.)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<?php
 if($_SERVER['REQUEST_METHOD'] == "POST") {
  $file = $_FILES['image']['name'];
  $servfile = $_FILES['image']['tmp_name'];
  echo "\$File: " . $file . "<br />";
  echo "\$servfile: " . $servfile . "<br /><br />";

  $filename = explode(".", $file);
  echo $filename[0] . "<br />";
  echo $filename[1] . "<br />";
  $filename[1] = strtolower($filename[1]);

  /* Begin execution once file extension is confirmed. */
  if ($filename[1] == "jpg" || $filename[1] == "gif" || $filename[1] == "png" || $filename[1] == "bmp") {
   echo "Successful recognition! <br />";
   crop($servfile, $filename[1], "280", "200");
  }
  /* Send back to main page with an error code. */
  else {
   echo "Error, dude!";
  }
 }

 function crop($filename, $type, $width, $height) {
  /* Create a new image from the proper filetype. */
  if ($type == "jpg") { $resource = imagecreatefromjpeg($filename); }
  if ($type == "gif") { $resource = imagecreatefromgif($filename); }
  if ($type == "png") { $resource = imagecreatefrompng($filename); }
  if ($type == "bmp") { $resource = imagecreatefrombmp($filename); }

  echo "Width is: " . imagesx($resource) . "<br />";
  echo "Height is: " . imagesy($resource) . "<br />";
  echo "Desired width is: " . $width . "<br />";
  echo "Desired height is: " . $height . "<br />";

  /* Check to make sure image is larger than needed size. */
  if ( ($width < imagesx($resource)) && ($height < imagesy($resource))) {
   echo "We can do this! <br />";


   $new = imagecreatetruecolor($width, $height);
   imagecopyresampled($new, $resource,
    0, 0, 0, 0, $width, $height, imagesx($resource), imagesy($resource));
    header('Content-type: image/jpeg');
    imagejpeg($new, "temp.jpg", 100);
    echo "<img src=\"temp.jpg\">";
  }
  /* Return with error that image is too small! */
  else { echo "Nope, not big enough."; }
  }
?>
</html>

Currently using WAMPSERVER running PHP 5.3.5.

The test server runs all PHP pages with no errors, except for this one that I have been battling for a few weeks now.

ADDED: The output in Internet Explorer is this when trying to upload an image named “8.jpg.” This is the actual view output by converter.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html> $File: 8.jpg<br />$servfile: C:\wamp\tmp\php82F0.tmp<br /><br />8<br />jpg<br />Successful recognition! <br />Width is: 1680<br />Height is: 1050<br />Desired width is: 280<br />Desired height is: 200<br />We can do this! <br /><img src="temp.jpg"></html>

Any help would be greatly appreciated, thank you.

  • 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-18T17:04:26+00:00Added an answer on June 18, 2026 at 5:04 pm

    There seems to be a problem when submitting the image for upload. This was either caused by the enctype in the form, or by the converter.php which was creating a header for mime_type of image/jpeg.

    Either way, after trying multiple browsers the code would never work, and Chrome would show the page as a broken image.

    I parsed the code and made converter.php an exclusive processing script with no output. This script then redirected to a new PHP page I sharply named ServedUp.php. The result was shown properly with newly resized images.

    I am unsure if this conflict was created in the script, or created somewhere in translation on the server side. Needless to say, the problem is now fixed.

    Thank you for everyone’s thoughts and opinions. I will be sure to use Stack Overflow again soon when another problem rises!

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

Sidebar

Related Questions

this is my first ever post here. I'm not sure if I've done the
enter code here My problem is this: in this database the junction table contains
I check like this: enter code here var point = new g.LatLng(parseFloat(lat),parseFloat(lng)); var bounds
enter code here Want to remove items from a Main list , but give
i have two dropdown list. first drop down:1 enter code here <form:select path=custName id=custName>
This is my first post so please go easy on me fellas. I am
enter code here My jquery ui dialog contains an iframe and has the option
enter code here I have a table on SQL server 2005 with bigint primary
enter code here Hi All, I have a simple windows service application that connects
enter code here I have a ListView that have a different Layout XML for

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.