function attach_update_attachment($attach_id, $attach_owner, $attach_post_id, $attach_filename, $attach_extension, $attach_size, $attach_downloads, $attach_mime, $attach_data)
{
    global $db, $pun_user, $pun_config;
    // fetch an unique name for the file
    $unique_name = attach_generate_filename($pun_config['attach_basefolder'] . '/' . $pun_config['attach_subfolder'] . '/', 0, $attach_size);
    // create a new file on disk and fill it with data...
    $newfile = fopen($pun_config['attach_basefolder'] . '/' . $pun_config['attach_subfolder'] . '/' . $unique_name, 'wb');
    //wb = write, reset file to 0 bytes if existing, and b is just for windows, to tell it's binary mode...is ignored on other OS:es
    if (!$newfile) {
        error('Error creating filepointer for file, for attachment with id: "' . $attach_id . '"', __FILE__, __LINE__);
    }
    // write the data into the file ...
    if (fwrite($newfile, $attach_data) === FALSE) {
        error('Error filling empty file with data, attachment with id: "' . $attach_id . '"', __FILE__, __LINE__);
    }
    fclose($newfile);
    // and close the file ...
    if (strlen($attach_mime) == 0) {
        $attach_mime = attach_create_mime(attach_find_extention($attach_filename));
    }
    // update the database with this info
    $result = $db->query('INSERT INTO ' . $db->prefix . 'attach_2_files (id,owner,post_id,filename,extension,mime,location,size,downloads) VALUES (\'' . $attach_id . '\',\'' . $attach_owner . '\',\'' . $attach_post_id . '\',\'' . $db->escape($attach_filename) . '\',\'' . $attach_extension . '\',\'' . $db->escape($attach_mime) . '\',\'' . $db->escape($pun_config['attach_subfolder'] . '/' . $unique_name) . '\',\'' . $attach_size . '\',\'' . $attach_downloads . '\')') or error('Unable to insert attachment record into database.', __FILE__, __LINE__, $db->error());
    return true;
}
Exemplo n.º 2
0
function create_attachment($name = '', $mime = '', $size = 0, $tmp_name = '', $post_id = 0, $message = 0)
{
    global $db, $panther_user, $panther_config;
    $unique_name = attach_generate_filename($panther_config['o_attachments_dir'], $message, $size);
    if (!move_uploaded_file($tmp_name, $panther_config['o_attachments_dir'] . $unique_name)) {
        error_handler(E_ERROR, 'Unable to move file from: ' . $tmp_name . ' to ' . $panther_config['o_attachments_dir'] . $unique_name, __FILE__, __LINE__);
    }
    if (strlen($mime) < 1) {
        $mime = attach_create_mime(attach_find_extention($name));
    }
    $insert = array('owner' => $panther_user['id'], 'post_id' => $post_id, 'filename' => $name, 'extension' => attach_get_extension($name), 'mime' => $mime, 'location' => $unique_name, 'size' => $size);
    $db->insert('attachments', $insert);
    return true;
}