因此,我查看了几乎所有问题,并尝试使用下面的 php 脚本显示我的图像。但它不起作用。我还尝试查看是否使用 PHPInfo() 启用了 GD 库并且它也可以正常工作。我对 PHP 很陌生,但似乎无法使其正常工作。谢谢你的帮助!
编辑:单击上传文档按钮后,我得到一个损坏的图像图标。
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_FILES['photo'])
&& is_uploaded_file($_FILES['photo']['tmp_name'])
&& $_FILES['photo']['error'] == UPLOAD_ERR_OK) {
foreach ($_FILES['photo'] as $key => $value) {
echo "$key : $value<br />";
}
if($_FILES['photo']['type'] == 'image/jpeg') {
$tmp_img = $_FILES['photo']['tmp_name'];
$image = imagecreatefromjpeg($tmp_img);
header('Content-Type: image/jpeg');
imagejpeg($image,NULL);
imagedestroy($image);
} else {
echo "Uploaded file ewas not a jpg image.";
}
echo "no photo uploaded.";
}
}
?>
<form enctype="multipart/form-data" action="book.php" method="post">
<input type="file" name="photo">
<input type="submit" value="upload a doc">
</form>