f-angi
7/13/2016 - 12:43 PM

Uploads a file using cURL

Uploads a file using cURL

	public function upload($filePath, $filename, $idDenuncia, $categoria) {
		$ch = curl_init ();
		
		$queryString = "?id_ds=$idDenuncia&categoria=$categoria&nome=$filename";
		$this->url .= $queryString;
		
		curl_setopt ( $ch, CURLOPT_URL, $this->url );
		curl_setopt ( $ch, CURLOPT_USERPWD, $this->username . ":" . $this->password );
		curl_setopt ( $ch, CURLOPT_POST, 1 );
		curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
// 		curl_setopt ( $ch, CURLOPT_VERBOSE, true );
		curl_setopt ( $ch, CURLOPT_POSTFIELDS, array (
				"allegato" => "@" . $filePath 
		));
		$resultJson = curl_exec ( $ch );
		curl_close ( $ch );
		$result = json_decode($resultJson, true);
		return $result["response"]["result"] == 1;
	}