Hello everybody,
I am working on a local module that once a course has a picture uploaded to the overview files area it creates a thumbnail and also a greyscale picture.
In order to get there I am first trying to get a copy of the already uploaded picture doing this:
$picture = $DB->get_record_select('files',"contextid = $context_id->id and filearea = 'overviewfiles' ,null, 'id,contenthash,pathnamehash,filename');
$fs = get_file_storage();
$filerecord = array('contextid'=>$system_context, 'component'=>'local_image', 'filearea'=>'thumbnail',
'itemid'=>0, 'filepath'=>'/', 'filename'=>$picture->filename,
'timecreated'=>time(), 'timemodified'=>time());
$original_picture = $fs->get_file_by_hash($picture->pathnamehash);
$stored = $fs->create_file_from_storedfile($filerecord,$picture->id);
This is creating an entry like this one in the database:
id | contenthash | pathnamehash | contextid | component | filearea | itemid | filepath | filename | userid | filesize | mimetype | status | source | author | license | timecreated | timemodified | sortorder | referencefileid |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3519875 | 2ea0e8ab9d835a0e0a04dd8e46266f510312c2df | 8f45605131ba6f3a6247bb35148c80acc6a95625 | 87418 | course | overviewfiles | 0 | / | 71ZIsWyQspL._SL1050_.jpg | 2 | 121931 | image/jpeg | 0 | 71ZIsWyQspL._SL1050_.jpg | Juan Carlos Giménez | allrightsreserved | 1563354618 | 1563354621 | 0 | |
3519924 | 2ea0e8ab9d835a0e0a04dd8e46266f510312c2df | 20ac9a4b6523e634e867b28122cf627564d8f981 | 1 | local_image | thumbnail | 0 | / | 71ZIsWyQspL._SL1050_.jpg | 121931 | image/jpeg | 0 | 71ZIsWyQspL._SL1050_.jpg | 1563362139 | 1563362139 | 0 |
I can see perfectly the picture
When I access the url:
pluginfile.php/1/local_image/thumbnail/71ZIsWyQspL._SL1050_.jpg
I get a code 200 and the browser shows a broken file as a result.
Can somebody give me a hand to know where is my error?