[英]Why doesn't my PHP recognize my file? Isset
嗨,我是PHP新手,正在尝试上传图片,为什么我的PHP无法识别我的文件? 我的代码不会通过以下行:
}else if(isset($_FILES['newspic'])) {
我的HTML低于
<form action="post.php" method="POST">
Please complete your PAP below:<br />
<textarea id="post" name="post" rows="4" cols="60"></textarea><br />
Web Link: <input type="text" name="weblink" value="http:\\www."><br />
Tag: <input type="text" name="tag"><br />
Post Image: <input type="file" name="newspic"><br />
<input type="submit" name="send" value="Post" />
</form>
添加:
enctype="multipart/form-data"
因此,完整的代码是:
<form action="post.php" method="POST" enctype="multipart/form-data">
Please complete your PAP below:<br />
<textarea id="post" name="post" rows="4" cols="60"></textarea><br />
Web Link: <input type="text" name="weblink" value="http:\\www."><br />
Tag: <input type="text" name="tag"><br />
Post Image: <input type="file" name="newspic"><br />
<input type="submit" name="send" value="Post" />
</form>
还要使用这个:
}else if(isset($_POST['newspic'])) {
要么
}else if(isset($_FILES["newspic"]["name"])) {
您需要在表单中添加一个enctype
才能发送文件。
<form action="post.php" method="post" enctype="multipart/form-data">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.