LiquidPlanner Classic Forum

Ask a Question
Back to All

How to get upload file path? PHP


Posted on behalf of Feng. Original posting date 2016-12-09.

Here is the code. And the question is how to get the correct $file_path? The file supposed to be located on the local folder. Thanks!

   $attachment_filename = "test.jpg";

  $file_path = "@$attachment_filename";

OR something like this:

    $attachment_filename= $_FILES['userfile']['name'] ; 

   $tmp_name                 = $_FILES['userfile']['tmp_name'];  

   $dest_dir  = 'upLoad';    

   $file_path = $dest_dir.'/'.$attachment_filename; 



.... your suggestion code


$upload_file_response = $lp->attachDocument($file_path,$attachment_filename, $task_id);
function attachDocument($file_path,$filename, $taskid) {
   $Data = array('document[attached_file]' => $file_path, 'document[file_name]'=> $filename);
   $url = $this->serviceurl . '/tasks/' . $taskid . '/documents';
   $response = $this->lp_attach_file($url, $Data);
function lp_attach_file($endpoint_url, $Data) {
   $curl = curl_init($endpoint_url);
   curl_setopt($curl, CURLOPT_HEADER, false);
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($curl, CURLOPT_USERPWD, trim($this->email).":".trim($this->password));
   curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type:     multipart/form-data"));
   curl_setopt($curl, CURLOPT_ENCODING, ""); // Prevent GZIP compression of response from LP
   curl_setopt($curl, CURLOPT_POST, true);
   curl_setopt($curl, CURLOPT_URL, $endpoint_url);
   curl_setopt($curl, CURLOPT_POSTFIELDS, $Data);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // Accept any SSL   certificate
   $response = curl_exec($curl);
   $error = curl_error($curl);
   $results = json_decode($response, true);
   return $results;