これがうまくいかない問題に対する私の解決策です。これは 4 つの異なる PHP ファイルで構成されており、1 つはフォーム、1 つはデータベースを更新するため、もう 1 つはイメージ ヘッダーを変更するためのもので、すべてを正しく最後に表示するようにします。
//create form
<h3>create person</h3>
<form action="create.php" method="post" enctype="multipart/form-data">
name:<input type="text" name="personname" value=""/>
info:<input type="text" name="personinfo" value=""/>
<br />
<br />
image:<input type="file" name="image" />
<input type="submit" name="submit" value="upload" />
</form>
<?php
$people = mysql_query("SELECT * FROM people", $connection);
if(!$people){
die("Failed: " . mysql_error());
}
while ($person = mysql_fetch_array($people)){
echo "<h1>{$person["name"]}</h1>";
echo "<p>{$person["info"]}</p>";
echo "<p>{$person["id"]}</p>";
echo "<P>{$person["img_name"]}</p>";
echo "<img src=getimage.php?id=" . urlencode($person["id"]) . ">";
echo "<br /><a href=\"Modify.php?personid=" . urlencode($person["id"]) . "\">Modify User</a>";
echo " ";
echo "<a href=\"delete.php?personid=" . urlencode($person["id"]) . "\">Delete User</a>";
}
?>
//creates image
<?php include 'includes/connection.php'; ?>
<?PHP
$name = $_POST['personname'];
$info = $_POST['personinfo'];
$img_name = addslashes($_FILES['image']['name']);
$image = imagecreatefromjpeg($_FILES['image']['tmp_name']);
$size = addslashes($_FILES['image']['size']);
$type = addslashes($_FILES['image']['type']);
$size2 = getimagesize($temp);
$width = $size2[0];
$height = $size2[1];
$newwidth = 100;
$ratio = $newwidth/$width;
$newheight = round($height * $ratio);
$new = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($new, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($image);
mysql_query("INSERT INTO people (`id`,`name`,`info`,`image`,`img_name`)
VALUES (NULL, '$name','$info','$new','$img_name')")or die(mysql_error);
header ('Location: adminarea.php?linkid=1');
?>
//display image
<?php include 'includes/connection.php'; ?>
<?php
$people = mysql_query("SELECT * FROM people", $connection);
if(!$people){
die("Failed: " . mysql_error());
}
while ($person = mysql_fetch_array($people)){
echo "<h1>{$person["name"]}</h1>";
echo "<p>{$person["info"]}</p>";
echo "<p>{$person["id"]}</p>";
echo "<P>{$person["img_name"]}</p>";
echo "<img src=getimage.php?id=" . urlencode($person["id"]) . ">";
echo "<br /><a href=\"Modify.php?personid=" . urlencode($person["id"]) . "\">Modify User</a>";
echo " ";
echo "<a href=\"delete.php?personid=" . urlencode($person["id"]) . "\">Delete User</a>";
}
?>
//change header of image
<?php Include 'includes/connection.php';?>
<?php
$id = addslashes($_GET['id']);
$image = mysql_query("SELECT * FROM people WHERE id = $id");
$image = mysql_fetch_assoc($image);
$image = $image['image'];
header("Content-type: image/jpeg");
echo $image;
?>