无法在PhP中获取要上载的文件

无法在PhP中获取要上载的文件,php,jquery,json,Php,Jquery,Json,我已将此添加到我的form_action.php中: if(isset($_FILES['attachment1'])){ $errors= array(); $file_name = $_FILES['attachment1']['name']; $file_size = $_FILES['attachment1']['size']; $file_tmp = $_FILES['attachment1']['tmp_name']; $file_type = $_FILES['

我已将此添加到我的form_action.php中:

if(isset($_FILES['attachment1'])){
  $errors= array();
  $file_name = $_FILES['attachment1']['name'];
  $file_size = $_FILES['attachment1']['size'];
  $file_tmp = $_FILES['attachment1']['tmp_name'];
  $file_type = $_FILES['attachment1']['type'];
  $file_ext=strtolower(end(explode('.',$_FILES['attachment1']['name'])));

  $expensions= array("jpeg","jpg","png","doc","pdf");

  if(in_array($file_ext,$expensions)=== false){
     $errors[]="extension not allowed, please choose a JPEG, PNG, PDF or DOC file.";
  }

  if(empty($errors)==true) {
     move_uploaded_file($file_tmp,"uploads/".$file_name);
     echo "Success";
  }else{
     print_r($errors);
  }
}
表单字段为

<form method="post" action="form_action1.php">
<div class="form-group">
     <label for="attachment1">Add file(s)</label>
     <input type="file" class="form-control-file" id="attachment1" aria-describedby="fileHelp" name="attachment1">
     <input type="file" class="form-control-file" id="attachment2" aria-describedby="fileHelp" name="attachment2">
     <input type="file" class="form-control-file" id="attachment3" aria-describedby="fileHelp" name="attachment3">       
 </div>
</form>

添加文件
路径已保存,但文件未上载。我是否错过了一个我不知道的步骤?另外,我可以在$\u FILES字段中设置一个数组以允许三次上载吗


这是我试图完成的个人项目的最后一步。谢谢。

您需要添加
enctype
,以便表单发布文件

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

发件人:

enctype

当method属性的值为post时,enctype是用于将表单提交到服务器的内容的MIME类型。可能的值为: application/x-www-form-urlencoded:未指定属性时的默认值

  • 多部分/表单数据:
    类型属性设置为“file”的元素所使用的值
  • text/plain
    (HTML5):此值可由或元素上的formenctype属性覆盖

包括完整表单“路径被保存”是什么意思?我在任何地方都看不到“保存路径”的代码。这可以简化为
if(空($errors)==TRUE)
if(!$errors){
…你添加了
enctype
了吗?@PraveenKumar是的,没有
enctype
,现在去回答便宜的问题吧points@cale_b谢谢。我不知道@Preveen的文件路径,我不知道
code
enctype实际上,这不起作用。可能是因为我把它添加到了我的整个PhP操作文件中吗?@SeanRawles你是怎么添加的?是吗对我来说一切看起来都是正确的。而且,老实说,为什么这会被否决?问问题不好吗?@SeanRawles这是在必要的信息不存在的时候提出的。顺便说一句,我没有否决。是的。不知道怎么做。再次尝试学习:D我确信我会得到它。