Upload file with Kaltura Client API (PHP)

Hello,
I am using Kaltura Client API(PHP) to develop a project, I met a problem:
I can not upload file(entry) to my kaltura server using client api, and the api wrote that:

“an exception will thrown when using one of the kaltura clients” ?!!

so how can i upload file to the kaltura server? I don’t want to use KMC. TAT

Thanks for the help from Jess Portnoy:
His reply:

Hello,

You can see an example here:
https://github.com/kaltura/platform-install-packages/blob/Jupiter-10.6.0/RPM/scripts/postinst/upload_test.php

And there are other useful examples in this dir as well.

May the source be with you,

Jess Portnoy

I try the example:
the front end code:

<form action="uploadProcess.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="hidden" name="MAX_FILE_SIZE" value="5000000000" />
<input type="file" name="file" id="file" onchange="document.getElementById('file_url').value=this.value;" /> 
<input type="text" name="file_url" id="file_url">
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>

the uploadProcess.php code:

require_once "php5/KalturaClient.php";
function upload($client,$fileData,$title,$conv_profile=null,$type=null)
{
	try{
		$uploadToken = new KalturaUploadToken();
		$result = $client->uploadToken->add($uploadToken);
		$tok=$result->id;
		$resume = null;
		$finalChunk = null;
		$resumeAt = null;
		$result = $client->uploadToken->upload($tok, $fileData, $resume, $finalChunk, $resumeAt);
		$entry = new KalturaBaseEntry();
		$entry->name = $title;
		if (isset($conv_profile)){
			$entry->conversionProfileId = $conv_profile;
		}
		if (!isset($type)){
			$type = KalturaEntryType::AUTOMATIC;
		}
		$result = $client->baseEntry->addfromuploadedfile($entry, $tok, $type);
		$id=$result->id;
		/*		$xme1=$client->getResponseHeaders();
		 $xme2=split(": ",$xme1[3]);
		 $xme=trim($xme2[1]);
		 echo $xme . " " .$title .' ';*/
		return($id);
	}catch(exception $e){
		/*		$xme1=$client->getResponseHeaders();
		 $xme2=split(": ",$xme1[3]);
		 $xme=trim($xme2[1]);
		 echo $xme . " " .$title .' ';*/
		throw $e;
	}
}
function generate_ks($service_url,$partnerId,$secret,$type=KalturaSessionType::ADMIN,$userId=null,$expiry = null,$privileges = null)
{
	$config = new KalturaConfiguration($partnerId);
	$config->serviceUrl = $service_url;
	$client = new KalturaClient($config);
	$ks = $client->session->start($secret, $userId, $type, $partnerId, $expiry, $privileges);
	$client->setKs($ks);
	return ($client);
}
$upload_dir = "../upload/";
$file_name = $_FILES["file"]["name"];
$file_tmp_name  = $_FILES["file"]["tmp_name"];
move_uploaded_file($file_tmp_name,$upload_dir . $file_name);

$entry_queue='/tmp/upload_test_queue';
$service_url = '';
$partnerId = ;
$secret='';
$asset_file =  $upload_dir . $file_name;

$client = generate_ks($service_url,$partnerId,$secret,$type=KalturaSessionType::USER,$userId=null);
$ext=explode(".",$asset_file);
$id=upload($client,$asset_file,date ("U",time()).'.'.$ext[3],null,null);
error_log($id."\n",3,$entry_queue);
echo $id."\n";

but when i run it ,it error:

Fatal error: Uncaught exception 'KalturaException' with message 'Upload failed' in D:\Apache24\htdocs\testUploadAndProcessBar\php5\KalturaClientBase.php:734 Stack trace: #0 D:\Apache24\htdocs\testUploadAndProcessBar\php5\KalturaClient.php(7662): KalturaClientBase->throwExceptionIfError(Array) #1 D:\Apache24\htdocs\testUploadAndProcessBar\uploadProcess.php(18): KalturaUploadTokenService->upload('0_3ca185f8292e8...', '../upload/10.wm...', NULL, NULL, NULL) #2 D:\Apache24\htdocs\testUploadAndProcessBar\uploadProcess.php(64): upload(Object(KalturaClient), '../upload/10.wm...', '1426051865.wmv', NULL, NULL) #3 {main} thrown in D:\Apache24\htdocs\testUploadAndProcessBar\php5\KalturaClientBase.php on line 734

what’s wrong ? Or I misunderstand the example.
@jess

Hello,

First, I edited your code to remove the service url and secret, please make certain never to share that.
Second, i would start by running the script from CLI and see if that works correctly. If not, check the /opt/kaltura/log/kaltura_api_v3.log on the server end to see what error you are getting.

Thanks,

Oh,Thanks. I forgot to remove them. I will notice next time.

I check the /opt/kaltura/log/kaltura_api_v3.log ,but found nothing useful… @ A @
Did you run it correctly ?

Every operation should be logged under /opt/kaltura/log/, usually, under kaltura_api_v3.log which is where the API V3 requests go to.
You can use the kaltlog command to see errors while making the requests.
If you are not seeing any requests being made then perhaps your client side cannot reach the server at all?

I use kaltlog command and found that:

[Wed Mar 11 15:42:58 2015] [error] [client 192.168.178.135] File does not exist: /opt/kaltura/web/content/docs/NetHelp/topic.css, referer:SERVER_URL /content/docs/NetHelp/default.htm

File does not exist, Oh TAT, how to pass a correct file as the param to the script ?
thanks.

This is not the cause of your issue…
do you even see your client request in /opt/kaltura/log/kaltura_apache_access*log?