Convert DOC to DOCX in PHP with Aspose.Words Cloud SDK for PHP

Hi,

I’ve tried to run the my first code in numerous ways for the last two days but no matter what I tried, I could not run it. So, here I’m.

I downloaded and installed the Aspose.Words-Cloud-SDK-for-PHP package with composer in the same directory with my php code.

After that I added following code (which I copied from documentation) into my php file:

$inputPath = getcwd() . “/TSG.doc”;

$fileName = basename($inputPath);

$outputPath = getcwd() . “/MyOutputFile1.docx”;

$appSID = “1b25*************”;

$appKey = “dca95************”;

$save_format = “docx”;

$strURI = “http://api.aspose.com/v1.1/words/convert?format=” . $save_format;

$signedURI = Sign($strURI, $appSID, $appKey);

$responseStream = uploadFileBinary($signedURI, $inputPath, ‘xml’);

saveFile($responseStream, $outputPath);

Note: I used complete appSID and appKey, not the above ones.

In the end, the only output I could get is the following message:

Fatal error: Call to undefined function Sign() in D:\XAMPP\htdocs\Login\new.php on line 75

I supposed that I should have added a require (or require_once) line at the beginning of my code because the “sign()” function propably belongs to Aspose API. So, I included all of api files in package into my “require” line, one by one. After that, I tried other packages, examples, etc from github and various combinations. Nothing has changed. I’ve received the same error message.

I miss something (or more) but what?

Which package should I download and where should I install it?

In my php code, how should I refer to Aspose API?

Do I ask wrong questions or is there any other question which I forget to ask?

Thanks in advance…

Hi Arhan,

Common methods like sign and uploadFileBinary are present inside Utils class. You can call them with reference to Utils e.g. Utils::sign

Please also check the tests folder at Aspose.Words Cloud SDK for PHP where a few tests are available for each API.

Best Regards,

@arhannur

Please use the ConvertDocument API method for DOC to DOCX conversion from Aspose.Words Cloud SDK for PHP. It converts documents from the request body and returns the result as a response stream. Secondly, the latest SDK is more simplified and improved. you do not need to worry about the API request authentication. Please check the sample PHP code for details.

<?php

require_once('D:\xampp\htdocs\aspose-words-cloud-php-master\vendor\autoload.php');


try {

	//TODO: Get your ClientID and ClientSecret at https://dashboard.aspose.cloud (free registration is required).		
	$ClientSecret="xxxxxxxxxxxxxxxxxxxxxxxxx";
	$ClientID="xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx";

	$wordsApi = new Aspose\Words\WordsApi($ClientID,$ClientSecret);
		
    	$format = "docx";
	$file = ("C:/Temp/02_pages.doc");
    
	$request = new Aspose\Words\Model\Requests\ConvertDocumentRequest($file, $format,null);
	$result = $wordsApi->ConvertDocument($request);	
	copy($result->getPathName(),"02_pages.docx");

        
} catch (Exception $e) {
    echo  "Something went wrong: ",  $e->getMessage(), "\n";
    PHP_EOL;
}

?>