예제 #1
0
function moveAttachment(&$row, $db, $from_prefix, $attachmentUploadDir)
{
    static $smf_folders = null;
    if ($smf_folders === null) {
        $request = $db->query("\n\t\t\tSELECT value\n\t\t\tFROM {$from_prefix}settings\n\t\t\tWHERE variable='attachmentUploadDir';");
        list($smf_attachments_dir) = $db->fetch_row($request);
        $smf_folders = @unserialize($smf_attachments_dir);
        if (!is_array($smf_folders)) {
            $smf_folders = array(1 => $smf_attachments_dir);
        }
    }
    // If something is broken, better try to account for it as well.
    if (isset($row['id_folder']) && isset($smf_folders[$row['id_folder']])) {
        $smf_attachments_dir = $smf_folders[$row['id_folder']];
    } else {
        $smf_attachments_dir = $smf_folders[1];
    }
    if (empty($row['file_hash'])) {
        $row['file_hash'] = createAttachmentFileHash($row['filename']);
        $source_file = $row['filename'];
    } else {
        $source_file = $row['id_attach'] . '_' . $row['file_hash'];
    }
    if (empty($row['mime_type'])) {
        $fileext = '';
        $mimetype = '';
        $is_thumb = false;
        if (preg_match('/\\.(jpg|jpeg|gif|png)(_thumb)?$/i', $row['filename'], $m)) {
            $fileext = strtolower($m[1]);
            $is_thumb = !empty($m[2]);
            if (empty($row['mime_type'])) {
                // AFAIK, all thumbnails got created as PNG
                if ($is_thumb) {
                    $mimetype = 'image/png';
                } elseif ($fileext == 'jpg') {
                    $mimetype = 'image/jpeg';
                } else {
                    $mimetype = 'image/' . $fileext;
                }
            }
        } else {
            if (preg_match('/\\.([a-z][a-z0-9]*)$/i', $row['filename'], $m)) {
                $fileext = strtolower($m[1]);
            }
        }
        if (empty($row['fileext'])) {
            $row['fileext'] = $fileext;
        }
        // try using getimagesize to calculate the mime type, otherwise use the $mimetype set from above
        $size = @getimagesize($filename);
        $row['mime_type'] = empty($size['mime']) ? $mimetype : $size['mime'];
    }
    copy_file($smf_attachments_dir . '/' . $source_file, $attachmentUploadDir . '/' . $row['id_attach'] . '_' . $row['file_hash'] . '.elk');
}
예제 #2
0
function moveAttachment($row, $db, $from_prefix, $attachmentUploadDir)
{
    static $smf_folders = null;
    if ($smf_folders === null) {
        $request = $db->query("\n\t\t\tSELECT value\n\t\t\tFROM {$from_prefix}settings\n\t\t\tWHERE variable='attachmentUploadDir';");
        list($smf_attachments_dir) = $db->fetch_row($request);
        $smf_folders = @unserialize($smf_attachments_dir);
        if (!is_array($smf_folders)) {
            $smf_folders = array(1 => $smf_attachments_dir);
        }
    }
    $smf_attachments_dir = $smf_folders[$row['id_folder']];
    if (empty($row['file_hash'])) {
        $row['file_hash'] = createAttachmentFileHash($row['filename']);
        $source_file = $row['filename'];
    } else {
        $source_file = $row['id_attach'] . '_' . $row['file_hash'];
    }
    copy_file($smf_attachments_dir . '/' . $source_file, $attachmentUploadDir . '/' . $row['id_attach'] . '_' . $row['file_hash'] . '.elk');
}