[英]Login and Registration using PHP & MySQL displays html tags in response
[英]PHP script using WAMP displays HTML output with tags
enter code here
这是我关于Stack Overflow的第一篇文章,所以如果我太含糊,请原谅我,并且没有为您提供必要的信息以立即诊断我的问题!
我创建了一个使用表单上载图像的临时页面。 表单然后发布到php页面,该页面对图像重新采样并创建一个新图像,并调整大小并裁剪。
我的问题是,在图像上传到的php页面上,所有PHP代码均正确发布并按我期望的方式运行,但所有HTML代码在浏览器中均未格式化。 我不确定为什么,我从来没有遇到过这个问题。
这是上传表单页面的代码:
<! 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); ?>
这是我处理PHP所遇到的问题,这使我遇到了问题并输出了所有HTML标记。 (请注意,PHP已处理且未在浏览器中显示。)
<!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>
当前使用运行PHP 5.3.5的WAMPSERVER。
测试服务器运行所有PHP页面都没有错误,除了我已经奋斗了几周的这一页之外。
添加:尝试上载名为“ 8.jpg”的图像时,Internet Explorer的输出是以下内容。 这是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>
任何帮助将不胜感激,谢谢。
提交图像进行上传时似乎存在问题。 这可能是由于表单中的enctype引起的,或者是由converter.php引起的 ,后者正在为image / jpeg的 mime_type创建头。
无论哪种方式,在尝试使用多种浏览器后,代码都将无法运行,Chrome会将页面显示为残破的图像。
我解析了代码,并使converter.php成为没有输出的专有处理脚本。 然后,此脚本重定向到一个新的PHP页面,我将其急剧命名为ServedUp.php 。 使用新调整大小的图像可以正确显示结果。
我不确定此冲突是在脚本中创建的,还是在服务器端翻译的某个位置创建的。 不用说,问题现在已经解决。
谢谢大家的想法和意见。 当出现另一个问题时,我将确保很快再次使用Stack Overflow!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.