简体   繁体   中英

Why doesn't my PHP recognize my file? Isset

Hi I am new to PHP and I am trying to upload an image, Why doesn't my PHP recognize my file? my code will not pass the following line:

}else if(isset($_FILES['newspic'])) {

My Html is below

<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>

Add this:

enctype="multipart/form-data"

So the full code is:

<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>

Also use this:

}else if(isset($_POST['newspic'])) {

or

}else if(isset($_FILES["newspic"]["name"])) {

您需要在表单中添加一个enctype才能发送文件。

<form action="post.php" method="post" enctype="multipart/form-data">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM