} unset($attachdata); $filepath = fetch_attachment_path($attachment['userid'], $attachment['attachmentid'], false, $vbulletin->options['pt_attachpath']); if (!is_readable($filepath) or @filesize($filepath) == 0) { $vbulletin->GPC['attacherrorcount']++; } $vbulletin->options['pt_attachfile'] = ATTACH_AS_DB; } else { // Converting FROM fs TO mysql $path = fetch_attachment_path($attachment['userid'], $attachment['attachmentid'], false, $vbulletin->options['pt_attachpath']); $thumbnail_path = fetch_attachment_path($attachment['userid'], $attachment['attachmentid'], true, $vbulletin->options['pt_attachpath']); $temp = $vbulletin->options['pt_attachfile']; $vbulletin->options['pt_attachfile'] = ATTACH_AS_DB; if ($filedata = @file_get_contents($path)) { $thumbnail_filedata = @file_get_contents($thumbnail_path); $attachdata =& vB_DataManager_Attachment_Pt::fetch_library($vbulletin, ERRTYPE_SILENT); $attachdata->set_existing($attachment); $attachdata->setr('filedata', $filedata); $attachdata->setr('thumbnail', $thumbnail_filedata); if (!($result = $attachdata->save())) { if (empty($attachdata->errors[0])) { $attacherror = fetch_error('upload_file_failed'); // change this error } else { $attacherror =& $attachdata->errors[0]; } } unset($attachdata); } else { // Add error about file missing.. $vbulletin->GPC['attacherrorcount']++;
/** * Additional data to update after a save call (such as denormalized values in other tables). * In batch updates, is executed for each record updated. * * @param boolean Do the query? */ function post_save_each($doquery = true) { $attachmentid =& $this->fetch_field('attachmentid'); $userid =& $this->fetch_field('userid'); $failed = false; // Check for filedata in an information field if (!empty($this->info['filedata'])) { $filename = fetch_attachment_path($userid, $attachmentid, false, $this->registry->options['pt_attachpath']); if ($fp = fopen($filename, 'wb')) { fwrite($fp, $this->info['filedata']); fclose($fp); #remove possible existing thumbnail in case no thumbnail is written in the next step. if (file_exists(fetch_attachment_path($userid, $attachmentid, true, $this->registry->options['pt_attachpath']))) { @unlink(fetch_attachment_path($userid, $attachmentid, true, $this->registry->options['pt_attachpath'])); } } else { $failed = true; } } if (!$failed and !empty($this->info['thumbnail'])) { // write out thumbnail now $filename = fetch_attachment_path($userid, $attachmentid, true, $this->registry->options['pt_attachpath']); if ($fp = fopen($filename, 'wb')) { fwrite($fp, $this->info['thumbnail']); fclose($fp); } else { $failed = true; } } ($hook = vBulletinHook::fetch_hook('ptattachdata_postsave')) ? eval($hook) : false; if ($failed) { if ($this->condition === null) { $this->condition = "attachmentid = {$attachmentid}"; $this->delete(); } // $php_errormsg is automatically set if track_vars is enabled $this->error('upload_copyfailed', htmlspecialchars_uni($php_errormsg)); return false; } else { parent::post_save_each(); return true; } }