Php 将文件从android应用程序上载到所需文件夹

Php 将文件从android应用程序上载到所需文件夹,php,mysql,Php,Mysql,我想在下面的特定文件夹中使用PHP从android应用程序上传文件,这是我尝试过的代码。 请帮助我这段代码有什么错误,并请建议我一些简单的解决方案,或者这个方法是正确的上传文件从android应用程序在serever上 $response = array(); if($_SERVER['REQUEST_METHOD']=='POST'){ //checking the required parameters from the request if(i

我想在下面的特定文件夹中使用PHP从android应用程序上传文件,这是我尝试过的代码。 请帮助我这段代码有什么错误,并请建议我一些简单的解决方案,或者这个方法是正确的上传文件从android应用程序在serever上

 $response = array();

    if($_SERVER['REQUEST_METHOD']=='POST'){

        //checking the required parameters from the request
        if(isset($_POST['exp']) && isset($_POST['employee_id']) && isset($_FILES['pdf']['name'])  ){

                //connecting to the database
            $con = mysqli_connect(DB_SERVER,DB_USER,DB_PASSWORD,DB_DATABASE) or die('Unable to Connect...');

            $resume_name = $_POST['exp'];
            $employee_id = $_POST['employee_id'];
            $file_data = $_FILES['pdf']['name'];

            $upload_path = 'Images/Employee_Profile_Picture/'.$employee_id.'/Resume/';

              //getting file info from the request
            $fileinfo = pathinfo($_FILES['pdf']['name']);

             //getting the file extension
            $extension = $fileinfo['extension'];

            //file url to store in the database
            $file_url = $upload_path . getFileName($employee_id). '.'. $extension;

            //file path to upload in the server
            $file_path = $upload_path . getFileName($employee_id);

         try{

            if(file_exists($upload_path))
            {
               $existing_file = glob($upload_path."/*.*");
               $empty_file = implode(" ",$existing_file);

              move_uploaded_file($_FILES['pdf']['name'],$upload_path) ;

    $sql = "UPDATE employee_registration SET resume_name ='$resume_name', resume_path='$file_url' where employee_id ='$employee_id'";

               //adding the path and name to database
               if(mysqli_query($con,$sql)){

                    //filling response array with values

                    $response['Success'] = "File Uploaded Successfully...!";
                    echo json_encode($response);

                }
                else
                {
                  $response['Error'] = "File Uploading Error...!";
                  echo json_encode($response);
                }

            }
                else
                {
                      mkdir('Images/Employee_Profile_Picture/'.$employee_id.'/Resume');
                      move_uploaded_file($_FILES['pdf']['name'],$upload_path) ;

        $sql = "UPDATE employee_registration SET resume_name ='$resume_name', resume_path='$file_url' where employee_id ='$employee_id'";

                            //adding the path and name to database
                            if(mysqli_query($con,$sql))
                            {

                             //filling response array with values

                                 $response['Success'] = "File Uploaded Successfully...!";
                                 echo json_encode($response);

                            }
                        else
                            {
                                $response['Error'] = "File Uploading Error...!";
                                echo json_encode($response);
                            }

                }
            }catch(Exception $e){
                $response['error']=true;
                $response['message']=$e->getMessage();
            }
    }

    }


      //here is my method getFileName

function getFileName($employee_id)
 {

   //mysql query to fetch data 
   $sql = mysql_query("SELECT resume_path from employee_registration where 
     employee_id = '$employee_id'") or die(mysql_error());
   while ($row = mysql_fetch_array($sql, MYSQL_ASSOC)) 
   {
     $response=$row['resume_path'];
   }
    $resume_name = explode("/", $response);
   echo $resume_name[4]; 
   return $resume_name;
  }
更改以下行:

move_uploaded_file($_FILES['pdf']['name'],$upload_path) ;

tmp_名称应用于上载文件,因为它具有临时存储文件的完整路径。其中,名称仅包含文件名,不包含任何路径信息。

更改以下行:

move_uploaded_file($_FILES['pdf']['name'],$upload_path) ;


tmp_名称应用于上载文件,因为它具有临时存储文件的完整路径。其中,作为名称仅包含文件名,不包含任何路径信息。

如果这不起作用
move\u upload\u文件($\u FILES['pdf']['tmp\u name'],$upload\u path)


请使用此文件内容($upload_path,$_FILES['pdf']['tmp_name'])

如果这不起作用
移动上传的文件($上传文件['pdf']['tmp\u名称'],$upload\u路径)


请使用此文件内容($upload_path,$_FILES['pdf']['tmp_name'])

问题是?编辑你的问题并添加一些描述来描述你的问题。否则,您的问题将被否决,问题是?编辑您的问题并添加一些描述来描述您的问题。否则你的问题会被否决