move files

move files

by idris alshikh -
Number of replies: 0

 Hi every one, I developed my mod plugin and I upload more than 700 images throw the editor element using Jquery so I implement files function to save and retrinve the images.

every thing work perfect after some time  some instance of my mod plugin dont shows the images and that because I used the mod id instead of the contextid I was think they are the same 

how can I correct this error the files upload with the rong contextid

I tray to do some think like that 

for every image 

file_prepare_draft_area (I use the old context)

file_save_draft_area_files( with the correct context)

my mudule name idris

function copyfile()

{

    global $DB;

//get every instace of my module

    $Idris= $DB->get_records('course_modules',array('module'=>"24"));

   foreach ($Idris as $idris)

   {

    

//get every image of my module instance

           $Images = $DB->get_records('idris_images', array('idrisid' => $idris->instance));

           $cm = get_coursemodule_from_id('idris', $idris->id);

           $context = context_module::instance($cm->id);

           foreach ($Images as $img) {

               $draftid = "";

                $draft = file_prepare_draft_area($draftid, $idris->instance, 'mod_idris', 'image', 0, null, $img->image);

                $img->image = file_save_draft_area_files($draftid, $context->id, 'mod_idris', 'imagenew', 0, null, $draft);

                 $DB->update_record('idris_images', $img) 

           }   

   }

}

but that don't work is my way correct and I have some problem or that way completely wrong?

Average of ratings: -