vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   How to add attachments from control panel? (https://vborg.vbsupport.ru/showthread.php?t=53052)

mADmAX` 05-17-2003 06:28 PM

How to add attachments from control panel?
 
I am trying to add something to the admin control panel to add attachments into the database without going through all the checks. This way (as I am the only admin), I can add attachments without having the checks etc, and no posts/threads.

What would be the code to add the file into the databse? I keep getting /var/tmp/xxxxxxxx kinda stuff and I know its not right.

mADmAX` 05-17-2003 07:04 PM

NM, figured it out I think...

I edited attachments.php and renamed it to what I want to use to pull those attachments...

It works well with zip files but no so well with images...

It says downloading picture for around 1-2 mins...then halts...

This is whats inside the php file.

PHP Code:

<?php
error_reporting
(7);

$noheader=1;

require(
"./global.php");

$attachmentinfo=$DB_site->query_first("SELECT filename,filedata,dateline
                            FROM dwipfiles
                            WHERE filesid='
$filesid'");

if (
$noshutdownfunc) {
  
$DB_site->query("UPDATE dwipfiles SET counter=counter+1 WHERE filesid='$filesid'");
} else {
  
$shutdownqueries[]="UPDATE LOW_PRIORITY dwipfiles SET counter=counter+1 WHERE filesid='$filesid'";
}

header("Cache-control: max-age=31536000");
header("Expires: " gmdate("D, d M Y H:i:s",time()+31536000) . "GMT");
header("Last-Modified: " gmdate("D, d M Y H:i:s",$attachmentinfo[dateline]) . "GMT");
header("Content-disposition: inline; filename=$attachmentinfo[filename]");
header("Content-Length: ".strlen($attachmentinfo[filedata]));
$extension=strtolower(substr(strrchr($attachmentinfo[filename],"."),1));

if (
$extension=='gif') {
  
header('Content-type: image/gif');
} elseif (
$extension=='jpg' or $extension=='jpeg') {
  
header('Content-type: image/jpeg');
} elseif (
$extension=='png') {
  
header('Content-type: image/png');
} elseif (
$extension=='pdf') {
  
header('Content-type: application/pdf');
} else {
  
header('Content-type: unknown/unknown');
}
echo 
$attachmentinfo[filedata];

?>


Boofo 05-17-2003 07:11 PM

If you get this figured out, I would be interested in trying it out. ;)

colicab-d 05-17-2003 08:10 PM

shouldnt be too hard, just create an edited attachment.php and put a form in it to add a new attachment and create a post id for it when you do so, or add an aditional filed to attachments like adminattachid and then you could insert them that way i guess

mADmAX` 05-17-2003 08:18 PM

Yeah I got it that far, it inserts it into the database...

But when you call from attachments.php like file (above)...

You can get the ZIP files, txt files BUT

On images, it just sits there saying Downloading picture.

It will never show the picture no matter how long I wait. unsure why. Is there soemthing special I have to do ?

mADmAX` 05-17-2003 08:20 PM

This is what I have in the upload section for the attachment..

PHP Code:

  $filesize=@filesize($getfile);
  
$filenum fopen($getfile,"rb");
  
$filestuff fread($filenum,$filesize);
  
fclose($filenum);

  
$DB_site->query("INSERT INTO dwipfiles (filesid,title,userid,pagetext,dateline,groupid,filename,filedata) VALUES (NULL,'".addslashes($title)."','$bbuserinfo[userid]','".addslashes($pagetext)."','".time()."','".addslashes($groupid)."','".addslashes($attachment_name)."','".addslashes($filestuff)."')"); 

Like I said, only pictures are giving me problems so maybe I need to add something special for them?

colicab-d 05-17-2003 08:20 PM

thats cause ur not inserting anything to filedata... ;) have a wee looky at the attachments table and see whats needED

mADmAX` 05-17-2003 08:22 PM

Its getting added into filedata, or I wouldnt be able to get the zip files, txt files :)

Let me post whole thing

mADmAX` 05-17-2003 08:24 PM

PHP Code:

// ###################### Start Upload #######################
if ($action=="uploadfile") {

  
doformheader("files","douploadfile",1);

  
maketableheader("Upload a New File");
  
makeuploadcode("File","getfile");

  
makechoosercode("File Group","groupid","filegroup",$files[groupid]);
  
makeinputcode("Name (optional)","title");

  
maketextareacode("File Text","pagetext","",25,120);

  
doformfooter("Upload Now");

}

// ###################### Start DoUpload #######################

// ###################### Start DoUpload #######################
if ($HTTP_POST_VARS['action']=="douploadfile") {

    
$getfile $HTTP_POST_FILES['getfile']['tmp_name'];

  
$attachment_name $HTTP_POST_FILES['getfile']['name'];

  
$HTTP_POST_VARS['action']="insertfile";
}

// ###################### Start Insert #######################
if ($HTTP_POST_VARS['action']=="insertfile") {

  
$filesize=@filesize($getfile);
  
$filenum fopen($getfile,"rb");
  
$filestuff fread($filenum,$filesize);
  
fclose($filenum);

  
$DB_site->query("INSERT INTO dwipfiles (filesid,title,userid,pagetext,dateline,groupid,filename,filedata) VALUES (NULL,'".addslashes($title)."','$bbuserinfo[userid]','".addslashes($pagetext)."','".time()."','".addslashes($groupid)."','".addslashes($attachment_name)."','".addslashes($filestuff)."')");

  
$action="modify";

  echo 
"<p>Record added</p>";



Like I said, it uploads it into the database, and I can call it out with attachment.php like page but images are either corrupt or missing a flag of some sort cause zip, txt files are fine.

mADmAX` 05-17-2003 08:27 PM

I have also verified the filedata column and its there even though you cant understand the code =P

colicab-d 05-17-2003 08:29 PM

why is it going into dwipfiles table? it should be put in the attachments table..

this is why ur getting probs as attachments.php isnt coded to remove file from any table, more the actual attachments table in the database..

well thats my hunch on looking at the code :D

colicab-d 05-17-2003 08:30 PM

you cant understand that code as its not ascii format :D its the format that the file uses.. diff for jpeg giff etc

mADmAX` 05-17-2003 08:33 PM

Its going into another table for a reason that is very complicated to explain (short form, be used for something totally different). I have renamed attachment.php to attachments.php. I have also edited the code to what is above when I first posted. As you can see it looks in dwipfiles now.

Either way, it doesnt explain the issue because only images are the probs I am having.

colicab-d 05-17-2003 08:38 PM

it could as if your calling these files back tru attachments.php then its set to be able to work with this table and there may be additional code for handling images , that isnt being parsed due to you using the data from a differemt table..

i say this as i know that there is all the stuff for showing images in threads etc.. tho im not sure if it in attachments.php..

but anyway if i am wrong then soz im stumped but the new table would maybe be it, as if attachments was able to take any data from anytable you might end up with some probs in theory..

anyway just an idea.. probs wrong lol

mADmAX` 05-17-2003 08:41 PM

You may be right, I have looked through any of the function calls and havent seen anything pointing there, but doesnt mean I haven't overlooked it. Just found it strange that ZIP and TXT files work fine, just images =\

Got me stumped bad ... lol

colicab-d 05-17-2003 08:44 PM

its also worth knowing that vb`d attachments work by having an attachment on every post, its just wether or not theres anything in the table ;)

found this out when making a gallery hack and kept getting lots of attachments with ids but no filedata or names etc ;)

( i echod the id to make sure of this)

mADmAX` 05-17-2003 08:50 PM

I took all the verifyid out and all the checks to ensure it wasnt it, calling it like this.

/attachments.php?filesid=33

I did something for the hell of it.

I uploaded through my script an attachment, then uploaded that same image through a post. So now both should hold the same filedata. The one shows up in a post. To see if it was getting corrupted in my upload script, I copied from dwipfiles (just that attachment filedata) over the one in attachment. Attachment still shows up fine and everything. So it appears its just the attachments.php file (my hacked one) to display images without the function call. I must be missing something =\

mADmAX` 05-17-2003 10:19 PM

Fixed it, for some reason I guess it dont like spaces to much and also needs an @ on a few...

Dunno why it only happened with images though /shrug

PHP Code:

$filesize=@filesize($getfile);
$filenum fopen($getfile,"rb");
$filestuff fread($filenum,$filesize);
fclose($filenum); 

Needed to be:

PHP Code:

$filesize=@filesize($filename);
$filenum=@fopen($getfile,"rb");
$filestuff=@fread($filenum,$filesize);
@
fclose($filenum); 


Boofo 05-17-2003 10:28 PM

What is the exact finished file then? And how do we use it from the Admin CP?

mADmAX` 05-17-2003 10:37 PM

Let me work a few bugs out to where you can edit afterwards, etc. and I will zip it up for you...

Boofo 05-17-2003 11:46 PM

Great! Thanks! You can pm it to me if you don't want to post it here. ;)

mADmAX` 05-18-2003 12:10 AM

Just make sure you are subscribed here so you get the update...shouldnt be long...tonight or tomorrow.

I just wanna make sure I stopped the crazy loop i just had, I dont wanna be responsible for it messing your database up :)

Boofo 05-18-2003 12:14 AM

Will be looking forward to it. Thanks, again. ;)

Dean C 05-18-2003 10:05 AM

Ok i have to ask this *subscribes to thread*

I've seen a few hackers use it around here...

What is this UPDATE LOW_PRIORITY stuff and $noshutdownfun :)?

- miSt


All times are GMT. The time now is 03:51 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01175 seconds
  • Memory Usage 1,819KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (24)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete