无法在php中发布FormData表单数据

时间:2018-03-26 15:37:40

标签: php mysql error-handling

我在此代码中使用Angular将formData发送到我的upload.php文件,然后从upload.php发送,将文件复制到另一个Direcrtory并将其地址插入MySQL音乐列表数据库,但我的代码不工作,甚至没有显示任何错误我不知道该怎么做 任何帮助都是值得赞赏的

 <body>
 <div class="container" ng-app="myapp" ng-controller="cntrl">
 <div class="col-md-4">
    <input type="file" file-input="files">
 </div>
 <div class="col-md-6">
 <button class="btn btn-info" ng-click="uploadfile()">upload</button>
 </div>
 </div>
 <div class="container" ng-app="myapp" ng-controller="cntrl">
 <div class="col-md-4">
    <input type="file" file-input="files">
 </div>
 <div class="col-md-6">
  <button class="btn btn-info" ng-click="uploadfile()">upload</button>
 </div>
 </div>
  </body>
   </html>
  <script>
  var app = angular.module("myapp",[]);
 app.directive("fileinput", function($parse){
        return{
            link : function($parse,element,attrs){
                element.on("change", function(event){
                     var files = event.target.files;
                     $parse(attrs.fileInput).assign(element[0].files);
                     $scope.apply();

                });

            }

        }

});
app.controller("cntrl",function($scope,$http){
    $scope.uploadfile = function(){
        var form_data= new FormData();
        angular.forEach($scope.files, function(file){

            form_data.append('file',file);


        });
        $http.post('upload.php', form_data,
        {

            transformRequest: angular.identity,
            headers{'Content-Type': undefined ,'Process-Data': false}
        }).success(function(response){
            alert(response);
        });

    }

});

upload.php代码

<?PHP

  $connect= mysqli_connect("localhost","root","","musiccloud");
 if(!empty($_FILES)){

$path='uploads/'.$_FILES['file'['name'];
if(move_uploaded_file($_FILES['file']['tmp_name'],$path))
{
    $Insertquery= "INSERT INTO musiclist(name) VALUES('".$_FILES['file'] 
 ['name']."')";
    if(mysqli_query($connect,$Insertquery))
    {

            echo 'file Uploaded';

    }
    else{

        echo 'file Not Uploaded';
    }


}

}

else{

echo 'some Error';
}
?>

0 个答案:

没有答案