How to check if the file uploaded is a video then do something [SOLVED] |
[eluser]Ludovic-r[/eluser]
Hi everyone! I'm working on a small opensource CMS for freelancers and I would like to know the code or the way to check if the file uploaded is a video then do something, let me explain : You have the upload field then you upload your video and in the controller (let's name it video_check) it checks if the file submitted is a video and if it is, do something. Any ideas ? It would be very very helpful! Many thanks!
[eluser]mi6crazyheart[/eluser]
You can use this codes to get the file extension of the uploading file before it'll get uploaded. Then, with that extension u can compare that with some video file extension... & if that file is a video file get match u can take appropriate action else allow to move forward... Ex: Code: <?php MOore info about phpinfo() : http://php.net/manual/en/function.pathinfo.php
[eluser]LuckyFella73[/eluser]
Or use the build-in function to get all data of the uploaded file by: Code: $info_file = $this->upload->data(); Check the user guide (bottom of page) to see what else fileinfo you can access with that function: http://ellislab.com/codeigniter/user-gui...ading.html
[eluser]Zorancho[/eluser]
Check application/config/mimes.php and you will see all of the supported file extensions by CI and do some googling to find out what are the possible values for video file.
[eluser]Ludovic-r[/eluser]
Many thanks! It's more than I've expect, I'll try this! I was thinking about something hard to trick this but actually it's really logic :/ shame on me :p
[eluser]Ludovic-r[/eluser]
Hm seems that I have a problem : I've done the manipulation with the if statement like : If my file_ext is equal to '.mov' > do something otherwise do another thing It doesn't work, here's my code : Code: if (! $this->upload->do_upload()) // Show some errors
[eluser]LuckyFella73[/eluser]
Try this: Code: if (! $this->upload->do_upload()) // Show some errors Hope that works - I didn't test.
[eluser]Ludovic-r[/eluser]
Unfortunately it doesn't work, no matter if I have a video or a picture the ($info_file['file_ext'] == '.mov') seems to not be recognized (I mean that it always go the the else statement even if I upload a video.mov) Any idea ? Btw thanks for your help! It's really appreciated!
[eluser]smilie[/eluser]
Hi, Is your file realy uploaded (do you see it on the server)? Also, do: print_r($this->upload->data()); to see what does CI get in it. Cheers, Smilie |
Welcome Guest, Not a member yet? Register Sign In |