Hello moodlers,
In my attempt to integrate PaintWeb (and here) in moodle I have stumbled upon a little obstacle when trying to handle files.
I use the following code:
$file_record = new object();
$file_record->contextid = $context->id; //5
$file_record->component = $component; //user
$file_record->filearea = $filearea; //user_draft
$file_record->itemid = $draftitemid; //randomly generated number
$file_record->filepath = $filepath; // /paintweb/
$file_record->filename = $filename; //radomlygenerated name.ext
$file_record->userid = $USER->id; //2
try {
$file = $fs->create_file_from_string($file_record, $imgdata);
} catch (Exception $err) {
paintweb_send_result($imgurl, $imgurlnew, false, $err->getMessage());
}
$binfo = $fbrowser->get_file_info($context, $component, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
if (empty($binfo)) {
paintweb_send_result($imgurl, $imgurlnew, false,get_string('moodleServer:saveFailed', 'paintweb'));
}
$imgurlnew = $binfo->get_url();
if (empty($imgurlnew)) {
paintweb_send_result($imgurl, $imgurlnew, false,
get_string('moodleServer:saveFailed', 'paintweb'));
}
Apparently, the file is saved on the first try but for some reason, the fileinfo cannot be fetched and the binfo variable remains empty. If I try to save again, an exception is caught which I suspect is caused by an attempt to overide the existing file. I imagine I should detect that before hand and treat it accordingly. For the first case though, when the file is saved, I'd like to understand why the file info cannot be retrieved...
Any idea ?
Thanks in advance!
Patrick Juhl