Exemple #1
0
echo $OUTPUT->heading_with_help($struploadpictures, 'uploadpictures', 'tool_uploaduser');
$mform = new admin_uploadpicture_form(null, $userfields);
if ($formdata = $mform->get_data()) {
    if (!array_key_exists($userfield, $userfields)) {
        echo $OUTPUT->notification(get_string('uploadpicture_baduserfield', 'tool_uploaduser'));
    } else {
        // Large files are likely to take their time and memory. Let PHP know
        // that we'll take longer, and that the process should be recycled soon
        // to free up memory.
        core_php_time_limit::raise();
        raise_memory_limit(MEMORY_EXTRA);
        // Create a unique temporary directory, to process the zip file
        // contents.
        $zipdir = my_mktempdir($CFG->tempdir . '/', 'usrpic');
        $dstfile = $zipdir . '/images.zip';
        if (!$mform->save_file('userpicturesfile', $dstfile, true)) {
            echo $OUTPUT->notification(get_string('uploadpicture_cannotmovezip', 'tool_uploaduser'));
            @remove_dir($zipdir);
        } else {
            $fp = get_file_packer('application/zip');
            $unzipresult = $fp->extract_to_pathname($dstfile, $zipdir);
            if (!$unzipresult) {
                echo $OUTPUT->notification(get_string('uploadpicture_cannotunzip', 'tool_uploaduser'));
                @remove_dir($zipdir);
            } else {
                // We don't need the zip file any longer, so delete it to make
                // it easier to process the rest of the files inside the directory.
                @unlink($dstfile);
                $results = array('errors' => 0, 'updated' => 0);
                process_directory($zipdir, $userfields[$userfield], $overwritepicture, $results);
                // Finally remove the temporary directory with all the user images and print some stats.
 if (!array_key_exists($userfield, $userfields)) {
     notify(get_string('uploadpicture_baduserfield', 'admin'));
 } else {
     // Large files are likely to take their time and memory. Let PHP know
     // that we'll take longer, and that the process should be recycled soon
     // to free up memory.
     @set_time_limit(0);
     @raise_memory_limit("192M");
     if (function_exists('apache_child_terminate')) {
         @apache_child_terminate();
     }
     // Create a unique temporary directory, to process the zip file
     // contents.
     $zipodir = my_mktempdir($CFG->dataroot . '/temp/', 'usrpic');
     $dstfile = $zipodir . '/images.zip';
     if (!$mform->save_file('userfile', $dstfile, true)) {
         notify(get_string('uploadpicture_cannotmovezip', 'admin'));
         @remove_dir($zipdir);
     } else {
         if (!unzip_file($dstfile, $zipdir, false)) {
             notify(get_string('uploadpicture_cannotunzip', 'admin'));
             @remove_dir($zipdir);
         } else {
             // We don't need the zip file any longer, so delete it to make
             // it easier to process the rest of the files inside the directory.
             @unlink($dstfile);
             $results = array('errors' => 0, 'updated' => 0);
             process_directory($zipdir, $userfields[$userfield], $overwritepicture, $results);
             // Finally remove the temporary directory with all the user images and print some stats.
             remove_dir($zipdir);
             notify(get_string('usersupdated', 'admin') . ": " . $results['updated']);