Welcome Guest, Not a member yet? Register   Sign In
How to check if the file uploaded is a video then do something [SOLVED]
#1

[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!
#2

[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
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');
$fileExtension = $path_parts['extension'] ;

if($fileExtension == 'Video file extension which you want to check')
{
Take appropriate action ;
}
else
{
Move ahead... ;
}

?>

MOore info about phpinfo() : http://php.net/manual/en/function.pathinfo.php
#3

[eluser]Ludovic-r[/eluser]
That sounds really logic, will try that! Thanks!
#4

[eluser]LuckyFella73[/eluser]
Or use the build-in function to get all data of the uploaded file by:
Code:
$info_file = $this->upload->data();

if ($info_file['file_ext'] == '.avi')
{
// this
}else{
// that
}

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
#5

[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.
#6

[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
#7

[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
        {
            $error = array('error' => $this->upload->display_errors());
                $this->load->view('upload/upload_form', $error);
        }
        elseif ($info_file['file_ext'] == '.mov') // If it's a video
        {

                $data = array(
                    'upload_data' => $this->upload->data(),
                    );
                $this->session->set_userdata($data);    
                $this->load->view('upload/upload_video', $data);
        }
        else // Otherwise do this :
        {

                $data = array(
                    'upload_data' => $this->upload->data(),
                    );
                $this->session->set_userdata($data);    
                $this->load->view('upload/upload_image', $data);
        }
#8

[eluser]LuckyFella73[/eluser]
Try this:
Code:
if (! $this->upload->do_upload()) // Show some errors
{
    $error = array('error' => $this->upload->display_errors());
    $this->load->view('upload/upload_form', $error);
}
else
{
    $data['upload_data'] = $this->upload->data();
    $this->session->set_userdata($data['upload_data']);

    if ($info_file['file_ext'] == '.mov') // If it's a video
    {
        $this->load->view('upload/upload_video', $data);
    }
    else // Otherwise do this :
    {
        $this->load->view('upload/upload_image', $data);
    }
}

Hope that works - I didn't test.
#9

[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!
#10

[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




Theme © iAndrew 2016 - Forum software by © MyBB