Announcement

Collapse
No announcement yet.

Attachment woes in 2.3.0 (including how I fixed it)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Attachment woes in 2.3.0 (including how I fixed it)

    My webserver is a Debian/testing box running fully updated software. Most importantly:

    apache 1.3.27.0-2
    mysql-server 4.0.13-2
    php4 4.1.2-6

    We had a catastrophic HD crash and had to start from scratch. I installed vB 2.3.0 and everything went just fine. Except one thing, attachments were simply not working. You could attach a file, it wouldn't give any warnings or errors, and it would say "soandso has attached this file" at the bottom of the post, but if you tried to open that attachment it would be a blank page or a broken image.

    First thing I checked was settings of course. I set the $tmppath for vB to /web/tmp and made that directory writable by the webserver. I set upload_tmp_dir in php.ini to /web/tmp as well. I made sure safe mode was off. I also double checked getimagesize() was functional, it was (attachments that were too large would give the usual error). Still, I made no progress.

    So I wrote a little 5 line HTML/10 line PHP script to just make sure uploading files via PHP even worked at all. This script, entirely seperate from vB, worked fine. Uploading files was certainly functional in it's most basic form.

    Then I took a look at the attachments table in the database. All of the columns were fine except for filedata. Filedata only had about 6-10 characters in it. The vast majority of the filedata was missing for some unknown reason.

    I pulled out admin/functions.php and started poking at the acceptupload() function. I simply had it print "$filestuff" and then exit before it inserts the filedata into the database. That worked fine. The $filestuff variable looked good. Something was happening between reading the file and inserting it into the database.

    Here is how I fixed it:

    First changed the way the file is read:
    PHP Code:
        // read file
        
    $filenum fopen($attachment,"rb");
        
    //$filestuff = fread($filenum,$filesize);
        
    while(!feof($filenum)) {
            
    $filestuff .= fread($filenum1024);
        }
        
    fclose($filenum);
        
    $filestuff addslashes($filestuff);
        
    $filestuff addcslashes($filestuff"\0"); 
    Then, since addslashes($filestuff) was already taken care of up there, I had to edit the INSERT slightly:
    PHP Code:
    $DB_site->query("INSERT INTO attachment (attachmentid,userid,dateline,filename,filedata,visible) \
    VALUES (NULL,
    $bbuserinfo[userid],".time().",'".addslashes($attachment_name)."','$filestuff','$visible')"); 
    After that, everything worked fine.

    What do you think? A bug or random voodoo? It seems my way of reading a file is superior, but I am not sure. All I know is that $filestuff was not making it into the database with the original code.

Related Topics

Collapse

Working...
X