Php函数文件上传不起作用,我怎么解决这个问题?

时间:2015-10-02 07:20:10

标签: php image file

$ _FILES提示我有点问题。我在控制器中使用此代码在用户输入中上传图像..

 public function actionAddequipment(){

  $model = new Equipment;
  $model -> equipment_title = $_POST['equipment_title'];
  $model -> equipment_sn = $_POST['equipment_sn'];
  $model -> equipment_type = $_POST['equipment_type'];
  $model -> user_id = $_POST['equipment_user_id'];
  $model -> equipment_utilities = $_POST['equipment_utilities'];
  $model -> equipment_date = date('Y-m-d H:i:s', Time());
  $model -> save();

   if (isset ($_POST['column'])){

     foreach($_POST['column'] as $key => $value){
        $model2 = new EquipmentColumnData;
     $model2 -> equipment_id = $model -> equipment_id;
     $model2 -> equipment_column_id = $key; 
     $model2 -> equipment_column_data_value = $value;
     $model2 -> save();

   }

  if(isset($_FILES)){

    if (!file_exists('../web/uploads/equipments/' . $model->equipment_id))
    mkdir('../web/uploads/equipments/' . $model->equipment_id, 0777,true);
    foreach($_FILES as $key => $value){
    $num=explode( '-', $key ); 
    if (!file_exists('../web/uploads/equipments/' . $model->equipment_id.'/'.$num[1]))
    mkdir('../web/uploads/equipments/' . $model->equipment_id.'/'.$num[1], 0777,true);
    move_uploaded_file($_FILES[$key]['tmp_name'], '../web/uploads/equipments/' . $model->equipment_id.'/'.$num[1]);


  }

  }



   }


}

}

但有一个问题。如果我上传图像,一切正常,命令保存,但图像不在我上传他的文件夹中。我怎么能解决这个问题? 谢谢你的回答! :)

1 个答案:

答案 0 :(得分:1)

检查move_uploaded_file的返回值,因为我敢打赌它会默默地失败并返回一个讨厌的false。然后查看move-uploaded-file文档并了解如何正确处理文件上传。