enter code here
これは、スタック オーバーフローに関する私の最初の投稿です。あいまいすぎて、問題をすぐに診断するために必要な情報を提供していない場合は、ご容赦ください。
フォームを使用して画像をアップロードする一時ページを作成しました。次に、フォームは、画像を再サンプリングし、サイズ変更およびトリミングされた新しい画像を作成する 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); ?>
これは、問題を引き起こし、すべての HTML タグを出力している PHP を処理するために私が持っているものです。(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>
どんな助けでも大歓迎です、ありがとう。