filePath = $filePath; $this->uploadURL = $uploadURL; if(is_array($otherParams) && $otherParams != false) { foreach ($otherParams as $fieldName => $fieldValue) { $this->postParams[$fieldName] = $fieldValue; } } $this->postParams[$formFileVariableName] = "\@".$filePath; } /* * function to upload file * if unable to upload file produce error and exit * else upload file */ function UploadFile () { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->uploadURL ); curl_setopt($ch, CURLOPT_POST, 1 ); print_r($this->postParams); curl_setopt($ch, CURLOPT_POSTFIELDS, $this->postParams); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST'); $postResult = curl_exec($ch); if (curl_errno($ch)) { print curl_error($ch); print "
Unable to upload file."; exit(); } else { } curl_close($ch); exit(); } } ?> This is the class file and the test file is as UploadFile(); // upload file with some post params //$objCurlFileUploader = new CurlFileUploader("/home/abhik/Desktop/Clipboard01.jpg", "http://website/fileUploaderTest.php",'file1', Array('test' => 'test1')); //$objCurlFileUploader->UploadFile(); ?>