MyBB Community Forums

Full Version: [B] Bug on functions_upload.php + a fix
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Somewhere on the upload_attachment you can find the following code:
        // All seems to be good, lets move the attachment!
        $filename = "post_".$mybb->user['uid']."_".TIME_NOW."_".md5(uniqid(rand(),ן¿½true)).".attach";
        //echo $filename."<br />";

        $file = upload_file($attachment, $mybb->settings['uploadspath']."/".$month_dir, $filename);

        // Failed to create the attachment in the monthly directory, just throw it in the main directory
        if($file['error'] && $month_dir)
        {
                $file = upload_file($attachment, $mybb->settings['uploadspath'].'/', $filename);
        }

        if($month_dir)
        {
                $filename = $month_dir."/".$filename;
        }

        ....

       // Lets just double check that it exists
        if(!file_exists($mybb->settings['uploadspath']."/".$filename))
        {
                $ret['error'] = $lang->error_uploadfailed.$lang->error_uploadfailed_detail.$lang->error_uploadfailed_lost;
                return $ret;
        }

The double check always failed because $filename is different between the time that the file is written and the time of the "double check" because of this line:

        if($month_dir)
        {
                $filename = $month_dir."/".$filename;
        }

For now I just comment out this line and it fixed the problem.
I can't reproduce any issues with attachments on 1.4.6 at all, works fine. Attachments are uploaded here on a daily basis and there haven't been any issues...
sandbird, you seize to relise that no body else is getting this issue, it is not mybb software.
it most likely is a corrupt file, or your host.
(2009-05-16, 07:33 PM)MattRogowski Wrote: [ -> ]I can't reproduce any issues with attachments on 1.4.6 at all, works fine. Attachments are uploaded here on a daily basis and there haven't been any issues...

Yes but there's a problem with this code on some installations (like on my server) and it should be fixed for everyone. I don't know the real case when it'll effect someone and when not - you must check this code because something is not right on it and I didn't have the time to fully examine the complete logic behind it.

I have a sub-directory 200905 on uploads.
Somehow the code expecting that any attachment will be placed inside it but the attachments goes to the main uploads directory.

The code to declare it to go into 200905 is this code:

$filename = $month_dir."/".$filename;

But it's located AFTER that the file already been uploaded (!)
OK the full complete fix after examining the logic:
        // Failed to create the attachment in the monthly directory, just throw it in the main directory
        if($file['error'] && $month_dir)
        {
                $file = upload_file($attachment, $mybb->settings['uploadspath'].'/', $filename);
        } else
        {
                if($month_dir)
                {
                        $filename = $month_dir."/".$filename;  
                }
        }
Please change it on newer versions.
Your fix makes no sense. Please do not use it.
You are saying there is a code problem but not really outlining what effect it has on the front end. Are attachments uploaded or not? Any problems with them?

The code mybb uses has a purpose and logic which apparently you don't understand.
(2009-05-16, 10:43 PM)labrocca Wrote: [ -> ]You are saying there is a code problem but not really outlining what effect it has on the front end. Are attachments uploaded or not? Any problems with them?

The code mybb uses has a purpose and logic which apparently you don't understand.

Who was that directed towards?
Toward the OP.