Ejemplo n.º 1
0
$mform = new admin_uploadpicture_form(null, $userfields);
if ($formdata = $mform->get_data()) {
    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.
        $zipdir = my_mktempdir($CFG->dataroot . '/temp/', 'usrpic');
        if (!$mform->save_files($zipdir)) {
            notify(get_string('uploadpicture_cannotmovezip', 'admin'));
            @remove_dir($zipdir);
        } else {
            $dstfile = $zipdir . '/' . $mform->get_new_filename();
            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.
Ejemplo n.º 2
0
/// Print the header
echo $OUTPUT->header();
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);