我有一个表单,该表单的操作是submit.php,即我试图在submit.php上执行的操作以上传文件图像,但是当我单击submit和print_r $ _FILE时,将出现一个空数组。我究竟做错了什么?我不想在与表单相同的页面上上传文件。形式如下:
<form action="in-the-press-submit.php" method="post">
<p>
<label for="title">Title:</label>
<input type="input" name="title" id="title">
</p>
<p>
<label for="posted-on">Posted On:</label>
<input type="date" name="posted-on" id="posted-on">
</p>
<p>
<label for="description" style="vertical-align:top;">Description:</label>
<textarea rows="20" cols="70" name="description" id="description"></textarea>
</p>
<p>
<label for="image">Image:</label>
<input type="file" name="image" id="image">
</p>
<p>
<input type="submit" name="submit" id="submit">
</p>
</form>
这是我在提交页面中的代码:
<?php
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"],
"/image-test/" . $_FILES["file"]["name"]);
echo "Stored in: " . "/image-test/" . $_FILES["file"]["name"];
}
?>
尝试这个
<form action="in-the-press-submit.php" method="post" enctype="multipart/form-data">
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句