Example #1
0
 /**
  * Moves the temporary file to its final destination.
  *
  * Michael Klier <*****@*****.**>
  */
 function _media_upload_action($data)
 {
     global $conf;
     if (is_array($data) && count($data) === 5) {
         io_createNamespace($data[2], 'media');
         if (rename($data[0], $data[1])) {
             chmod($data[1], $conf['fmode']);
             media_notify($data[2], $data[1], $data[3]);
             // add a log entry to the media changelog
             if ($data[4]) {
                 addMediaLogEntry(time(), $data[2], DOKU_CHANGE_TYPE_EDIT);
             } else {
                 addMediaLogEntry(time(), $data[2], DOKU_CHANGE_TYPE_CREATE);
             }
             return $data[2];
         } else {
             return new IXR_ERROR(1, 'Upload failed.');
         }
     } else {
         return new IXR_ERROR(1, 'Upload failed.');
     }
 }
Example #2
0
/**
 * Saves an uploaded media file
 *
 * @author Andreas Gohr <*****@*****.**>
 * @author Michael Klier <*****@*****.**>
 */
function media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite)
{
    global $conf;
    global $lang;
    // prepare directory
    io_createNamespace($id, 'media');
    if (move_uploaded_file($fn_tmp, $fn)) {
        // Set the correct permission here.
        // Always chmod media because they may be saved with different permissions than expected from the php umask.
        // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.)
        chmod($fn, $conf['fmode']);
        msg($lang['uploadsucc'], 1);
        media_notify($id, $fn, $imime);
        // add a log entry to the media changelog
        if ($overwrite) {
            addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_EDIT);
        } else {
            addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_CREATE);
        }
        return $id;
    } else {
        msg($lang['uploadfail'], -1);
    }
}
Example #3
0
/**
 * Saves an uploaded media file
 *
 * @author Andreas Gohr <*****@*****.**>
 * @author Michael Klier <*****@*****.**>
 * @author Kate Arzamastseva <*****@*****.**>
 */
function media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite, $move = 'move_uploaded_file')
{
    global $conf;
    global $lang;
    global $REV;
    $old = @filemtime($fn);
    if (!@file_exists(mediaFN($id, $old)) && @file_exists($fn)) {
        // add old revision to the attic if missing
        media_saveOldRevision($id);
    }
    // prepare directory
    io_createNamespace($id, 'media');
    if ($move($fn_tmp, $fn)) {
        @clearstatcache(true, $fn);
        $new = @filemtime($fn);
        // Set the correct permission here.
        // Always chmod media because they may be saved with different permissions than expected from the php umask.
        // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.)
        chmod($fn, $conf['fmode']);
        msg($lang['uploadsucc'], 1);
        media_notify($id, $fn, $imime, $old);
        // add a log entry to the media changelog
        if ($REV) {
            addMediaLogEntry($new, $id, DOKU_CHANGE_TYPE_REVERT, sprintf($lang['restored'], dformat($REV)), $REV);
        } elseif ($overwrite) {
            addMediaLogEntry($new, $id, DOKU_CHANGE_TYPE_EDIT);
        } else {
            addMediaLogEntry($new, $id, DOKU_CHANGE_TYPE_CREATE, $lang['created']);
        }
        return $id;
    } else {
        return array($lang['uploadfail'], -1);
    }
}
Example #4
0
/**
 * Saves an uploaded media file
 *
 * @author Andreas Gohr <*****@*****.**>
 * @author Michael Klier <*****@*****.**>
 */
function media_upload_finish($fn_tmp, $fn, $id, $imime)
{
    global $conf;
    global $lang;
    // prepare directory
    io_createNamespace($id, 'media');
    if (move_uploaded_file($fn_tmp, $fn)) {
        // Set the correct permission here.
        // Always chmod media because they may be saved with different permissions than expected from the php umask.
        // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.)
        chmod($fn, $conf['fmode']);
        msg($lang['uploadsucc'], 1);
        media_notify($id, $fn, $imime);
        return $id;
    } else {
        msg($lang['uploadfail'], -1);
    }
}