douer9399 2014-05-06 15:07
浏览 7
已采纳

文件上传到另一页面

I have a form and the action of the form is submit.php, what I am trying to do on submit.php to upload a file image, but when I click submit and print_r $_FILE an empty array appears. What am I doing wrong? I dont want to upload the file on the same page as the form. Here is the form:

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

and here is my code in the submit page:

<?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"];
  }

?>
  • 写回答

4条回答 默认 最新

  • douhuai4155 2014-05-06 15:11
    关注

    Try this

    <form action="in-the-press-submit.php" method="post" enctype="multipart/form-data">
    

    Documentation : http://www.w3schools.com/php/php_file_upload.asp

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分