Hey, I'm making a website and I have a section where users can upload images, I want these images to have their full size image as well as a scaled down counterpart stored inside of the userUploads/images folder. The scaled images can be generated very easily by running a pretty simple FFMPEG command to scale the images down to like 100px with their same aspect ratio so these previews can be displayed while the full images are loading. All the javascript and html and such is working to the point of image uploads into a folder, but now I'm trying to figure out how I can detect when something is uploaded to this folder and run FFMPEG on that image and create an imageName-small.ext, does anyone have any ideas as to how I could go about building this? Either some sort of listener for file uploads and run a specific start command when that happens, or some traceback listener through the logs? Either way what would be the best way to start on a project like this? What scripting language would be useful? I'm on a windows machine, does that matter at all should I be using bash cmds? or can I write an executable program in like C++ or something to run in the background and listen to when the logs show that a file has been uploaded, and in that case where is the output that something has uploaded to the site in php? I know this is a far out question but I hope someone has some guidance, I appreciate any and all input, thank you!
#Trying to Link FFMPEG to File Uploads
23 messages · Page 1 of 1 (latest)
the actual downsize of the image is really simple in cmd it's cd (whichever directory the images are stored) then just
ffmpeg -i imageName.jpg -vf scale=100:-1 imageName-small.jpg
so the actual implementation of getting the downscaled images should be pretty simple as long as I can run a bash cmd from the program
What are you uploading to? Is there a form that's being handled on the server side?
I'm uploading to a local folder on my pc which eventually will be the server, but site side the images are being handled by a form which on submit has a js listener that calls an ajax function to call a php file to upload the images to my local machine/the actual server side; so short answer yes? The images are being processed and checked server side then being actually uploaded into the storage for the site (currently it's really not super organized with a mix of site images and profile images, but that can be organized pretty easy)
I'll snap a photo of the site heirarchy
inside of userUploads/images is where the images get uploaded to
I need to somehow listen for when a new image has been uploaded to that images folder and call FFMPEG based off it but I'm not sure how I could possibly set up a listener outside of the site to run the bash command that I need
Can't the PHP that's handling the upload start FFMPEG???
can it?
interesting, I just looked it up and you can shell_exec from php, that
that's pretty damn cool, I didn't know that
thank you Zech!
Np
I'll try it out and hopefully the solution really is that simple, I appreciate it, thank you for the help!
Just make sure you're very careful
Opening up any user provided input into your program and your operating system.
Yea absolutley, #1 rule of security don't trust any user input at all ever, I'll have quite a few checks to make sure the file is a valid image file and nothing else
especially with putting something on my os I have to be absolutley sure it's not a script file or any other type of file that could potentially corrupt the system
as well as name checks and all that
clean the name of all special characters and such so when the name does come up in php as a variable it doesn't somehow execute a sql statement or some snippet of php code or something somehow
is there anything else I should be doing in order to take precaution besides those three? making sure it's a true valid image file, making sure the name is cleaned of all special characters/anything that could potentially execute, and ensuring the image file is not corrupted in some sort of way?