سلام.
من می خوام در پاسخ به درخواست وب سرویس به کاربر فایل برگردونم. این کدیه که برای نمونه نوشتم. ( بعضی از جزییات کم اهمیت رو حذف کردم. )
class local_wstemplate_external extends external_api { public static function hello_world_parameters() { ... } public static function hello_world($token) { ... Authentications ... $fs = get_file_storage(); // Prepare file record object $fileinfo = array( 'component' => 'user', // usually = table name 'filearea' => 'private', // usually = table name 'itemid' => 0, // usually = ID of row in table 'contextid' => 5, // ID of context 'filepath' => '/', // any path beginning and ending in / 'filename' => 'a.txt'); // any filename // Get file $file = $fs->get_file($fileinfo['contextid'], $fileinfo['component'], $fileinfo['filearea'], $fileinfo['itemid'], $fileinfo['filepath'], $fileinfo['filename']); // Read contents $contents = $file->get_content(); return $contents; } public static function hello_world_returns() { return new external_value( PARAM_TEXT, 'File!'); } }
و دارم به این وب سرویس با پروتکل RPC وصل میشم :
curl -k -d "<?xml version='1.0' encoding='utf-8'?><methodCall><methodName>local_wstemplate_hello_world</methodName><params> <param> <value> <string>f5b0854a870e05f960cff39fc2a40665</string> </value> </param></params></methodCall>" https://localhost/moodle/webservice/xmlrpc/server.php?wstoken=f5b0854a870e05f960cff39fc2a40665
درخواستا برای فایلای تکست درست کار میکنن ولی وقتی میخوام فایلای دیگه مثل زیپ یا هر فایل دیگه ای که کاراکتر خاص داره بفرستم ارور زیر رو میده و نمیدونم باید نوع خروجی رو چی بزارم یا چیکار کنم که درس کار کنه :
<?xml version="1.0" encoding="UTF-8"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>28260048</int></value></member><member><name>faultString</name><value><string>Invalid response value detected | DEBUG INFO: Invalid external api response: the value is "PK</string></value></member></struct></value></fault></methodResponse>
لطفا راهنماییم کنید. ممنون.