嗨,我正试图创建一个表单,按照一些网络示例加载图像,但我无法加载图像。我正在处理我的个人软帽盒运行apache。对于Apache,是否有一些设置需要我做不同的处理?这是我应该上传图像的表单脚本:
<form name ="input" enctype="multipart/form-data" action = "addPhotograph.php" method = "get">
<table>
<tr>
<th>Title:</th> <td><input type="text" name ="photoname"></td>
</tr>
<tr>
<th>Photograph:</th> <td><input type="file" id="file" name="file" accept="image/*"></td>
</tr>
<tr>
<th>Photographer:</th><td><input type="" name="photographer"></td>
</tr>
<tr>
<th>Genre:</th><td><input type = "" name="genre"></td>
</tr>
<table>
<input type="submit" value = "Submit">
</form>
这是我的PHP脚本:
<?php
$uploaddir = '/var/www/html/photodb';
$uploadfile = $uploaddir . basename($_FILES['file']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['file']['name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.'n";
} else {
echo "Possible file upload attack!'n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>
当我通过表单添加图像时,php表单会失败,并显示"可能的文件上传攻击!"我想这意味着要么文件无法移动,要么文件没有上传?
我这样做是为了我的大学作业,任何回应或其他想法都将不胜感激:)。
将方法更改为POST:
<form name ="input" enctype="multipart/form-data" action = "addPhotograph.php" method = "post">
您不能通过GET方法发布文件。
为什么不使用表单post?
<form name ="input" enctype="multipart/form-data" action = "addPhotograph.php" method = "post">