MyBB Community Forums

Full Version: 'attachment.php' .attach file necessary?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
currrent attach url is


Quote:~/attachment.php?aid=90

not

Quote:/uploads/201808/post_1_1535168838_4cb9cc848adcfc900dasdzxc8b8dba7a.mp4

To get the attached file directly.

 I add this code in attachment.php 


Quote:header('Location: '.$mybb->settings['uploadspath']."/".$attachment['attachname']);


Otherwise, uploaded images or mp4 are loaded every time I viewed, When using the full size of the image in posting.

not cached at all, traffic wasted

So I changed .



Is there a problem with this method?
There isn't a problem with your method if it works but it's probably not the best way of doing it. I haven't tested it, but I'd probably make a similar change to the $handle variable here. It should give you the same result.
First of all there is an issue with this: Everybody knowing the actual URL of the file can download it even without having the permission to view attachments.

Also does this actually work? Browsers usually have no idea what to do with a file having the ".attach" file extension. They will prompt to download the file and Windows won't know how to open it.
(2018-08-25, 06:40 AM)StefanT Wrote: [ -> ]First of all there is an issue with this: Everybody knowing the actual URL of the file can download it even without having the permission to view attachments.

Also does this actually work? Browsers usually have no idea what to do with a file having the ".attach" file extension. They will prompt to download the file and Windows won't know how to open it.


download permission issue is fine.

I allow only images and mp4 (to reduce the capacity of gif) on my site.

So I am more concerned with whether images are cached or not.

So in function_upload.php, I changed [file.attach] to [file.jpg ,file.mp4] 


function_upload.php

.
.
.
//gif to mp4 when uploading with ffmpeg

$filename = "post_".$mybb->user['uid']."_".TIME_NOW."_".md5(random_str()).".attach";
$filename = preg_replace('"\.attach$"', '.mp4', $filename); 

$ffmpeg = "/usr/bin/ffmpeg";
$gifFile = $attachment['tmp_name'];

$output = $mybb->settings['uploadspath']."/".$month_dir."/".$filename;
$cmd = "$ffmpeg -i $gifFile -movflags faststart -pix_fmt yuv420p -vf \"scale=trunc(iw/2)*2:trunc(ih/2)*2\" $output";

exec($cmd);   
$attachment['name'] = $output;
.
.
.



function upload_file($file, $path, $filename="")
.
.
//$moved = @move_uploaded_file($file['tmp_name'], $path."/".$filename);
.
.

It works well.


(2018-08-25, 05:34 AM)Wires Wrote: [ -> ]There isn't a problem with your method if it works but it's probably not the best way of doing it. I haven't tested it, but I'd probably make a similar change to the $handle variable here. It should give you the same result.


	while(!feof($handle))
	{
		echo fread($handle, 8192);
	}
	fclose($handle);

I think that Because of this part, image files inserted into the post in full size (especially large gif files) are newly loaded.
caching works fine for me even if the file is served through attachment.php

for raw files, caching also depends on the webserver settings

edit: oh, it actually doesn't work on community.mybb.com