PHP Photo and Video Uploader (help me pls)
#8656
hello all i'm finding myself at a bit of a mental block right now and was hoping to get some advice on something for zeniea

i'm trying to add the ability to post both images and videos in one upload script. right now i basically have like two buttons with two different functions and it's a hacky piece of shit that does not work well and i do not like it. i'd just like some ideas on a direction to head in to make this all work in one go so i don't keep moving forward with this terrible idea i'm having right now.

it's basically just check if file is too large, check file type, and then the move uploaded file function. afterwards the link to that file is put into the database and included in the post formatting but since it's like an image include i didn't think i could just lump it in there so i made a separate function for videos and a separate database column and i think it's just overdoing it.

any ideas on how to make this more efficient?
#8657
you could use mime_content_type along with a set of allowed types to determine how it's embedded in the post
video types are usually prefixed with "video/" and image types with "image/" which lets you almost be lazy with insertions, there's some exceptions where it uses an "application/" prefix in which case you should add some kinda exception, MDN maintains a list of common ones https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types

this is the code i have in the chat for inserting the link with the appropriate bbcode

if(fileInfo.type.indexOf('image/') === 0) {
insertText = '[img]' + fileInfo.url + '[/img]';
thumb.style.backgroundImage = 'url(\'%\')'.replace('%', fileInfo.thumb);
thumb.classList.remove('hidden');
} else if(fileInfo.type.indexOf('audio/') === 0) {
insertText = '[audio]' + fileInfo.url + '[/audio]';
} else if(fileInfo.type.indexOf('video/') === 0) {
insertText = '[video]' + fileInfo.url + '[/video]';
}


fileInfo.type here is from json i have returned when an upload finishes successfully, for example;

{
"id": "aWG2NDmxz4GapUEEgVE1gm07RMX2d97l",
"url": "//i.flashii.net/aWG2NDmxz4GapUEEgVE1gm07RMX2d97l",
"urlf": "//eeprom.flashii.net/uploads/aWG2NDmxz4GapUEEgVE1gm07RMX2d97l",
"thumb": "//i.flashii.net/aWG2NDmxz4GapUEEgVE1gm07RMX2d97l.t",
"name": "1581826672-oeqAZPM.png",
"type": "image/png",
"size": 1228757,
"user": 1,
"hash": "fc9e98c6f93c1d39266e20dd8fc39a7004fc6c7a3ebf572e32aaa8398576d781",
"created": "2020-03-02T02:06:22+00:00",
"accessed": "2020-03-02T02:56:46+00:00",
"expires": "2021-03-02T08:56:46+00:00",
"deleted": null,
"dmca": null
}

https://flash.moe/signature/signature.php?p=bodyhttps://flash.moe/signature/signature.php?p=album
#8664
this simple thing helped out a ton and i've got it mostly functional right now. i'm still gonna experiment with file types and allowed size but as of right now it uploads and includes properly

another thing is figuring out how much gold should be awarded for media posts since right now the algorithm is awarded based on post length and some other internal variables and i don't wanna over-reward based on file size or anything cause that could be exploited easily.
#8665
i'm glad it helped
as for the other question; perhaps you could reencode the files using ffmpeg or something after submission so any excess data is cut off, this would also allow you to cap resolutions so people can't just pop off with 5 second 4k videos
i've never done something like this myself so i can't provide any examples sadly
https://flash.moe/signature/signature.php?p=bodyhttps://flash.moe/signature/signature.php?p=album